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

Cookie-Consent-Using-Bootstrap

How to Create a Simple Cookie Banner Consent Using Bootstrap 4

Cookie Consent Popup Javascript – Quick and simple tutorial for creating a simple Bootstrap cookie banner. If you have a website or blog with people visiting or…

Create-HTML-Terminals

Create Custom HTML Terminals With Pure JavaScript | shell.js

Custom HTML Terminals is A JavaScript library to create HTML terminals on web pages. The shell js JavaScript library offers a straightforward method to create Ubuntu, OS X,…

Bootstrap-Alert-Bootbox

Bootstrap Alert, Confirm, and Flexible Dialog Boxes | Bootbox

Bootbox.js is a small JavaScript library that allows you to create programming dialogs using Bootstrap templates, without having to worry about creating, managing, or removing any required…

Slider-fg-carousel

An Accessible Touch-enabled Slider Web Component | fg-carousel

fg-carousel Slider – A simple & modern slider web component to create versatile, accessible, touch-enabled picture carousels utilizing CSS scroll snap, Custom Element, and Intersection Observer API….

Tags-Input-Component

A Lightweight and Efficient Tags Input Component in Vanilla JS | tagify

tagify transforms an input field or textarea into a tags component, in an easy and customizable way, with great performance and a small code footprint, full of…

copy-to-clipboard-javascript

A Lightweight Library to Copy Text to Clipboard | CopyJS

CopyJS is a lightweight JavaScript library that allows you to copy plain text or HTML content to the clipboard. Must Read: Tiny Library for Copy Text In…