mdelrosso / sheepit

SheepIt! Form Cloning plugin for Jquery
http://www.mdelrosso.com/sheepit/
MIT License
68 stars 44 forks source link

normalizeFieldsForForm() function through an error #47

Open walid-ajaj opened 2 years ago

walid-ajaj commented 2 years ago

https://github.com/mdelrosso/sheepit/blob/7318e91e951ff139cf02a05bcc7901ec762b0d15/jquery.sheepItPlugin.js#L155

normalizeFieldsForForm() function through an error in case the element (input) had no name or id attributes

Below is my suggestion for the fix:

                var that = $(this)
                    ,idTemplateAttr = getOrSetTemplate(that,"id")
                    ,nameTemplateAttr = getOrSetTemplate(that, "name")
                    ,idAttr = that.attr("id")
                    ,nameAttr = that.attr("name")

                /* Normalize field name attributes */
                newNameAttr = nameTemplateAttr ? nameTemplateAttr.replace(options.indexFormat, index) : nameAttr;
                that.attr("name", newNameAttr);

                /* Normalize field id attributes */
                newIdAttr = idTemplateAttr ? idTemplateAttr.replace(options.indexFormat, index) : idAttr;

                idAttr ? form.find("label[for='"+idAttr+"']").each(function(){
                    $(this).attr("for", newIdAttr);
                }) : null;
                that.attr("id", newIdAttr);