Dynamic form elements generate with jQuery

Overview

Clone Form Preview

Demo

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/3.3.2/select2.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.3.2/select2.css">
<script src="cloneData.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">


<div class="container">
    <h3>NOTE: If you are using any third party plugin then you must add following class to initiate.</h3>
    <ol>
        <li>Bootstrap Datepicker: add class into input "<span class="text-danger">datepicker-init</span>"</li>
        <li>Ckeditor: add class into input "<span class="text-danger">ckeditor-init</span>"</li>
        <li>Select2: add class into input "<span class="text-danger">select2-init</span>"</li>
        <li>Chosen Dropdown: add class into input "<span class="text-danger">chosen-init</span>"</li>
    </ol>


    <div class="margin-t-md">
        <div class="customer-form">
            <h3>Dynamic Form</h3>
            <form id="" action="submit.php" method="post" role="form" autocomplete="off">
                <div class="row">
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="control-label" for="customer-first_name">First name</label>
                            <input type="text" id="customer-first_name" class="form-control" name="Customer[first_name]"
                                   maxlength="32" aria-required="true" placeholder="Rajneesh">
                            <p class="help-block help-block-error"></p>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="control-label" for="customer-last_name">Last name</label>
                            <input type="text" id="customer-last_name" class="form-control" name="Customer[last_name]"
                                   maxlength="64" aria-required="true" placeholder="Gautam">
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="control-label" for="customer-email">Email</label>
                            <input type="text" id="customer-email" class="form-control" name="Customer[email]"
                                   maxlength="32" aria-required="true" placeholder="[email protected]">

                            <p class="help-block help-block-error"></p>
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="control-label" for="customer-mobile">Mobile</label>
                            <input type="text" id="customer-mobile" class="form-control" name="Customer[mobile]" placeholder="9935723456">
                        </div>
                    </div>
                </div>

                <div id="main-container">
                    <div class="panel panel-default">

                        <div class="panel-body container-item">
                            <fieldset class="item panel panel-default" style="border: 1px solid black; padding: 10px;">
                                <!-- widgetBody -->
                                <legend style="width: auto;padding:10px;">Address: 1</legend>
                                <div class="panel-body">
                                    <div class="form-group">
                                        <label class="control-label" for="full_name_0">Full Name</label>
                                        <input type="text" id="full_name_0" class="form-control"
                                               name="Address[0][full_name]" maxlength="128" placeholder="Full Name">
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label class="control-label" for="address_line_one_0">Address line
                                                    1</label>
                                                <input type="text" id="address_line_one_0" class="form-control"
                                                       name="Address[0][address_line1]" placeholder="Address Line 1">
                                                <p class="help-block help-block-error"></p>
                                            </div>
                                        </div>
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label class="control-label" for="city_0">City</label>
                                                <input type="text" id="city_0" class="form-control"
                                                       name="Address[0][city]" maxlength="64">
                                                <p class="help-block help-block-error"></p>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label class="control-label" for="customer-startdate_0">Start Date</label>
                                                <input type="text" id="customer-startdate_0" class="form-control datepicker-init" name="Address[0][startdate]">
                                            </div>
                                        </div>

                                        <div class="col-sm-6">
                                            <div class="form-group">
                                                <label class="control-label" for="state_0">State</label>

                                                <select id="state_0" class="form-control select2-init" name="Address[0][state]">
                                                    <option value="" data-select2-id="2">Select a state ...</option>
                                                    <optgroup label="Alaskan/Hawaiian Time Zone">
                                                        <option value="AK">Alaska</option>
                                                        <option value="HI">Hawaii</option>
                                                    </optgroup>
                                                    <optgroup label="Pacific Time Zone">
                                                        <option value="CA">California</option>
                                                        <option value="NV">Nevada</option>
                                                        <option value="OR">Oregon</option>
                                                        <option value="WA">Washington</option>
                                                    </optgroup>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="form-group">
                                                <textarea name="Address[0][desc]" id="desc_0" class="ckeditor-init"
                                                          rows="5" cols="80"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div>
                                                <a href="javascript:void(0)"
                                                   class="remove-item btn btn-sm btn-danger remove-social-media">Remove</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                        </div>

                    </div>
                </div>
                <hr>
                <div class="row">
                    <div class="col-sm-6">
                        <a href="javascript:;" class="pull-right btn btn-success btn-xs" id="add-more"><i class="fa fa-plus"></i>
                            Add more address</a>
                        <div class="clearfix"></div>
                    </div>

                    <div class="col-sm-6">
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </div>
                </div>


            </form>
        </div>
    </div>
</div>


<script>
    $('a#add-more').cloneData({
        mainContainerId: 'main-container', // Main container Should be ID
        cloneContainer: 'container-item', // Which you want to clone
        removeButtonClass: 'remove-item', // Remove button for remove cloned HTML
        removeConfirm: true, // default true confirm before delete clone item
        removeConfirmMessage: 'Are you sure want to delete?', // confirm delete message
        //append: '<a href="javascript:void(0)" class="remove-item btn btn-sm btn-danger remove-social-media">Remove</a>', // Set extra HTML append to clone HTML
        minLimit: 2, // Default 1 set minimum clone HTML required
        maxLimit: 5, // Default unlimited or set maximum limit of clone HTML
        defaultRender: 1, // Number of clone items rendered by default 
        init: function () {
            console.info(':: Initialize Plugin ::');
        },
        beforeRender: function () {
            console.info(':: Before rendered callback called');
        },
        afterRender: function () {
            console.info(':: After rendered callback called');
        },
        afterRemove: function () {
            console.warn(':: After remove callback called');
        },
        beforeRemove: function () {
            console.warn(':: Before remove callback called');
        }
    });

    $('.select2').select2({
        placeholder: 'Select a month'
    });
</script>
You might also like...

Save time by managing bills & expenses, invoicing & easy reconciliation all in one app. Generate clear dynamic statements and get your reports, the way you like them

Save time by managing bills & expenses, invoicing & easy reconciliation all in one app. Generate clear dynamic statements and get your reports, the way you like them

expense-manager-app (Opensource Expense Tracking App built with React) 🔥 Save time by managing bills & expenses, invoicing & easy reconciliation all

Oct 12, 2022

Horizontal Timeline 2.0, a fully customisable jQuery plugin to create a dynamic timeline on the horizontal axis.

Horizontal Timeline 2.0 by yCodeTech Twitter @yCodeTech Current Version: 2.0.5.3 Quick Links: Setup | Options | Autoplay | Known Issues | Known Issues

May 29, 2022

Generate deterministic fake values: The same input will always generate the same fake-output.

Generate deterministic fake values: The same input will always generate the same fake-output.

import { copycat } from '@snaplet/copycat' copycat.email('foo') // = '[email protected]' copycat.email('bar') // = 'Thurman.Schowalter668@

Dec 30, 2022

The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support.

 The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support.

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

Dec 30, 2022

Javascript library for switching fixed elements on scroll through sections. Like Midnight.js, but without jQuery

Library for Switching Fixed Elements on Scroll Sometimes designers create complex logic and fix parts of the interface. Also they colour page sections

Sep 19, 2022

The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support

The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

Dec 30, 2022

A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes!

(jQuery) Uniform A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes! Works well with jQuery 1.6+, but we

Jan 2, 2023

The jQuery plugin for validation and post form data to server

NiceForm The jQuery plugin for validation and post form data to server (http://ducdhm.github.io/jquery.niceform/) Shortcuts Dependencies Rules Configu

Jul 27, 2022

A jQuery plugin that creates a countdown timer in years, months, days, hours and seconds in the form a bunch of rotating 3d cubes

CountdownCube is a jQuery plugin that is in the form of a bunch of rotating 3D cubes. It uses CSS transitions to create the 3D rotating cube effects.

Mar 6, 2022
Comments
  • check the select value on change

    check the select value on change

    I'd like to chek the select value with jquery in change. I code this little js for this :

    $('state_' + index).on('change', function() { alert( $(this).find(":selected").val() ); });

    But it doesn't seem to work. Any tips please ?

    opened by devaliere 0
  • want tempate functionality

    want tempate functionality

    suppose we put a out html row as below

    <div id="main-container">
      <div class="container-item">
        <label class="control-label" for="address_line_one_0">Address</label>
        <input type="text" id="address_line_one_0" name="Address[0][address_line]">
        <textarea name="Address[0][desc]" id="desc_0"></textarea>
        ... More Form Fields Here ...
      </div>
    </div>
    

    But in .container-item can we add {0} or any other format that is also incremented by click add so we can apply some conditional CSS

    opened by circuitmamu 0
  • hide remvoe button on first element or index

    hide remvoe button on first element or index

    I want to set that when page initiate with my form row with 3 element that is being copied when add button click and a remove button is there for each row but I want to hide remove button for first row or index 0

    opened by circuitmamu 0
Releases(v1.0)
FormGear is a framework engine for dynamic form creation and complex form processing and validation for data collection.

FormGear is a framework engine for dynamic form creation and complex form processing and validation for data collection. It is designed to work across

Ignatius Aditya Setyadi 91 Dec 27, 2022
jQuery-plugin for add/remove dom-items with renaming form-elements (arrays)

dynamicrows jQuery-plugin for add/remove rows by cloning existing row / renaming form-elements (arrays). Requirements jQuery >=2.0 if move-action used

Dennis Dohle 0 Nov 9, 2020
Form To CSS - jQuery-Plugin form to CSS generator

Create your own CSS generator with the form to css generator Builder plugin. Can be usefull to create your own css builder or a Wordpress plugin or any kind of apps you need a real time css generator. For example, you can create a button generator

Gino 4 Sep 26, 2021
Dynamic-web-development - Dynamic web development used CSS and HTML

Dynamic-web-development ASSISNMENT I just used CSS and HTML to make a mobile int

null 1 Feb 8, 2022
dynamic-component-app is an angular application for dynamic component template creation

MyApp This project was generated with Angular CLI version 14.1.0. Development server Run ng serve for a dev server. Navigate to http://localhost:4200/

Aniket Muruskar 7 Aug 26, 2022
Auth-Form-Design - Beautiful Auth Form Designed using React 🥰.

?? Auth Form Design ?? Features 1. Check Your Password Strength 2. Can Use Suggested Password 3. Enjoy Responsive Design Getting Started with Create R

Samarpan Dasgupta 2 Dec 24, 2022
Gatsby-Formik-contact-form-with-backend-panel - Full working contact form with backend GUI panel.

Gatsby minimal starter ?? Quick start Create a Gatsby site. Use the Gatsby CLI to create a new site, specifying the minimal starter. # create a new Ga

Bart 1 Jan 2, 2022
This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Kanshi TANAIKE 18 Oct 23, 2022
A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

form-storage A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again. Installation via npm npm install

appleple 159 Dec 10, 2022
generate pages from markdown files with dynamic routes, 0 effort, 0 boilerplate.

next-markdown Markdown Pages for Next.js Dynamic Routes. Blog Aware. Design Your Layout Made for people having a nextjs project in ❤️ with markdown wh

François Rouault 105 Oct 11, 2022