Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3966550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:36:52+00:00 2026-05-20T03:36:52+00:00

Im using the jQuery dynamic form plugin , but i need support for nested

  • 0

Im using the jQuery dynamic form plugin, but i need support for nested field duplication.

I would like some advice on how to modify the plugin to add such functionality.
Im not a javascript/jQuery developer, so any advice on which route to take will be much appreciated.

I can provide the plugin’s code:

/**
 * @author Stephane Roucheray
 * @extends jQuery
 */

jQuery.fn.dynamicForm = function (plusElmnt, minusElmnt, options){
    var source = jQuery(this),
    minus = jQuery(minusElmnt),
    plus = jQuery(plusElmnt),
    template = source.clone(true),
    fieldId = 0,
    formFields = "input, checkbox, select, textarea",
    insertBefore = source.next(),
    clones = [],
    defaults = {
        duration:1000
    };

    // Extend default options with those provided
    options = $.extend(defaults, options);

    isPlusDescendentOfTemplate = source.find("*").filter(function(){
        return this == plus.get(0);
    });

    isPlusDescendentOfTemplate = isPlusDescendentOfTemplate.length > 0 ? true : false;

    function normalizeElmnt(elmnt){
        elmnt.find(formFields).each(function(){
            var nameAttr = jQuery(this).attr("name"), 
            idAttr = jQuery(this).attr("id");

            /* Normalize field name attributes */
            if (!nameAttr) {
                jQuery(this).attr("name", "field" + fieldId + "[]");
            }

            if (!/\[\]$/.exec(nameAttr)) {
                jQuery(this).attr("name", nameAttr + "[]");
            }

            /* Normalize field id attributes */
            if (idAttr) {
                /* Normalize attached label */
                jQuery("label[for='"+idAttr+"']").each(function(){
                    jQuery(this).attr("for", idAttr + fieldId);
                });

                jQuery(this).attr("id", idAttr + fieldId);
            }
            fieldId++;
        });
    };

    /* Hide minus element */
    minus.hide();

    /* If plus element is within the template */
    if (isPlusDescendentOfTemplate) {
        function clickOnPlus(event){
            var clone,
            currentClone = clones[clones.length -1] || source;
            event.preventDefault();

            /* On first add, normalize source */
            if (clones.length == 0) {
                normalizeElmnt(source);
                currentClone.find(minusElmnt).hide();
                currentClone.find(plusElmnt).hide();
            }else{
                currentClone.find(plusElmnt).hide();
            }

            /* Clone template and normalize it */
            clone = template.clone(true).insertAfter(clones[clones.length - 1] || source);
            normalizeElmnt(clone);

            /* Normalize template id attribute */
            if (clone.attr("id")) {
                clone.attr("id", clone.attr("id") + clones.length);
            }


            plus = clone.find(plusElmnt);
            minus = clone.find(minusElmnt);

            minus.get(0).removableClone = clone;
            minus.click(clickOnMinus);
            plus.click(clickOnPlus);

            if (options.limit && (options.limit - 2) > clones.length) {
                plus.show();
            }else{
                plus.hide();
            }

            clones.push(clone);
        }

        function clickOnMinus(event){
            event.preventDefault();

            if (this.removableClone.effect && options.removeColor) {
                that = this;
                this.removableClone.effect("highlight", {
                    color: options.removeColor
                }, options.duration, function(){that.removableClone.remove();});
            } else {

                this.removableClone.remove();
            }
            clones.splice(clones.indexOf(this.removableClone),1);
            if (clones.length == 0){
                source.find(plusElmnt).show();
            }else{
                clones[clones.length -1].find(plusElmnt).show();
            }
        }

        /* Handle click on plus */
        plus.click(clickOnPlus);

        /* Handle click on minus */
        minus.click(function(event){

        });

    }else{
    /* If plus element is out of the template */
        /* Handle click on plus */
        plus.click(function(event){
            var clone;

            event.preventDefault();

            /* On first add, normalize source */
            if (clones.length == 0) {
                normalizeElmnt(source);
                jQuery(minusElmnt).show();
            }

            /* Clone template and normalize it */
            clone = template.clone(true).insertAfter(clones[clones.length - 1] || source);
            if (clone.effect && options.createColor) {
                clone.effect("highlight", {color:options.createColor}, options.duration);
            }
            normalizeElmnt(clone);

            /* Normalize template id attribute */
            if (clone.attr("id")) {
                clone.attr("id", clone.attr("id") + clones.length);
            }
            if (options.limit && (options.limit - 3) < clones.length) {
                plus.hide();
            }
            clones.push(clone);
        });

        /* Handle click on minus */
        minus.click(function(event){
            event.preventDefault();
            var clone = clones.pop();
            if (clones.length >= 0) {
                if (clone.effect && options.removeColor) {
                    that = this;
                    clone.effect("highlight", {
                        color: options.removeColor, mode:"hide"
                    }, options.duration, function(){clone.remove();});
                } else {
                    clone.remove();
                }
            }
            if (clones.length == 0) {
                jQuery(minusElmnt).hide();
            }
            plus.show();
        });
    }

};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:36:53+00:00Added an answer on May 20, 2026 at 3:36 am

    At the end, I found a plugin that does what I need and seems to work fine.

    SheepIt

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Jquery dynamic form plugin to generate dynamic fields in one of
I have a form which is built dynamically using this jQuery plugin http://code.google.com/p/jquery-dynamic-form/ When
I'm currently using the jquery dynamic form plugin to add form fields. http://sroucheray.org/blog/jquery-dynamic-form/ My
I am using the jQuery autocomplete plugin and have wired up an input field
I am using jQuery Form Plugin to submit (POST) a WebForm. Everything works great
I'm using the Jquery Validation Plugin to forms loaded via Ajax (dynamic forms). I
Using jquery how do I focus the first element (edit field, text area, dropdown
Using jQuery, what's the best way to find the next form element on the
Using jQuery, how would you find elements which have a particular style (eg: float:
When using jQuery 's ajax method to submit form data, what is the best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.