A Lightweight Plugin for Binding/Linking JSON Data to Forms

JQuery-JSON-Form-Fields is a lightweight plug-in for linking JSON data to forms. Useful for working with AJAX and forms that contain a large number of fields.

JSON-form -inding.js is a plugin for creating a jQuery dynamic form that can be used to populate form fields with JSON data. Ideal for large forms with which you can quickly submit form data with AJAX.

populate form with json data jquery, populate html form with json data, jquery populate form fields from json, fill form with json data

How to make use of it:

1. Insert the minified version of the jQuery JSON-form-binding.js plugin after jQuery.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" 
        integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" 
        crossorigin="anonymous">
</script>
<script src="jquery-json-form-binding.min.js"></script>

2. Create your individual type fields with distinctive names:

<div id="banner-message">
 <form id="myform">
        <div class="form-field">
            <h5>
                Text Input
            </h5>
            <input type="" name="name">
        </div>

        <div class="form-field">
            <h5>
                Single Select
            </h5>
            <select name="country">
                <option value="usa">USA</option>
                <option value="uk">UK</option>
                <option value="germany">Germany</option>
            </select>
        </div>

        <div class="form-field">
            <h5>
                Multiple Select
            </h5>
            <select multiple name="skill">
                <option value="html">html</option>
                <option value="css">css</option>
                <option value="javascript">javascript</option>
                <option value="node">node</option>
            </select>
        </div>

        <div class="form-field">
            <h5>
                checkbox example
            </h5>
            <label>
                <input type="checkbox" value="english" name="language" />English</label>
            <label>
                <input type="checkbox" value="french" name="language" />French</label>
            <label>
                <input type="checkbox" value="german" name="language" />German</label>
        </div>


        <div class="form-field">
            <h5>
                Radio example
            </h5>
            <label>
                <input type="radio" value="male" name="sex" />Male</label>
            <label>
                <input type="radio" value="female" name="sex" />Female</label>
        </div>
    </form>
</div>

3. Call the function on the HTML form and outline your type information in a JSON object utilizing key/value pair as follows:

// jsonToForm library
$.fn.jsonToForm=function(a,c){var l=this,n={data:a||null,callbacks:c};null!=n.data&&$.each(n.data,function(a,c){var e=$('[name="'+a+'"]',l);null!=n.callbacks&&n.callbacks.hasOwnProperty(a)?n.callbacks[a](c):(e.length||c.length)&&$(e).each(function(n,e){Array.isArray(c)?c.forEach(function(a){$(e).is("select")?$(e).find("[value='"+a+"']").prop("selected",!0):$(e).val()==a&&$(e).prop("checked",!0)}):$(e).is(":checkbox")||$(e).is(":radio")?$(e).val()==c&&$(e).prop("checked",!0):$('[name="'+a+'"]',l).val(c)})})};

(function() {
  var json = {
                name: "Waleed",
                country: "uk",
                skill: ["html", "javascript"],
                language: ["english", "german"],
                sex: "female"
            };

            $("#myform").jsonToForm(json);
            
            console.log($("#myform").serialize());
})();

Populate Form Fields With JSON Data, JQuery-JSON-Form-Fields Plugin/Github


See Demo And Download

Official Website(devWaleed): Click Here

This superior jQuery/javascript plugin is developed by devWaleed. For extra advanced usage, please go to the official website.

Related Posts

Floating-Whatsapp-Chat-Button

How to Add Floating Whatsapp Chat Button In HTML | venom-button

Venom Button is a very simple plugin for the jQuery floating WhatsApp button. Adds a floating button to your site that calls WhatsApp Click to Chat API. It will automatically start the WhatsApp…

Data-Table-Generator-Tabulator

Interactive Data Table Generator with JS/jQuery and JSON | Tabulator

Tabulator allows you to create interactive tables in seconds from any HTML Table, JavaScript array, AJAX data source, or JSON format data. Just include the library in your…

alert-confirm-prompt-attention-js

Simple Alert, Confirm, Prompt Popup Using Vanilla JavaScript Library | attention.js

JavaScript provides various built-in functionality to display popup messages for different purposes. Attention JS is a vanillaJS plugin used to create a custom alert, confirm, or Prompt…

Bootstrap-4-Sidebar-Menu-Responsive-Template

Bootstrap 4 Sidebar Menu Responsive Template | MDB

Bootstrap Side Navbar – Responsive sidebar template based on the Bootstrap 4 framework. An easy-to-use, totally responsive, Google Material Design impressed aspect navigation for modern web app…

Bootstrap-4-Toast-Notification-Plugin

Lightweight Bootstrap 4 Toast Notification Plugin | BS4 Advanced Toast

A lightweight Bootstrap 4 Toast Notification plugin integrated with JS/jQuery. bs4-toast.js is a JavaScript library that enhances the native Bootstrap toast component with icons, buttons, callbacks, and…

Audio-Visualizations-Wave

How to Create Audio Visualizations with JavaScript | Wave.js

Audio Visualizer Library – wave.js is a vanilla javascript audio visualization library that provides 20+ creative audio visualization effects to bring more engagement to your visitor. Contribute…

Leave a Reply

Your email address will not be published. Required fields are marked *