StratusForms icon indicating copy to clipboard operation
StratusForms copied to clipboard

Multiple Repeatables problem

Open plbowers opened this issue 5 years ago • 0 comments

I note issue #15 which was fixed by 1.55a - code follows:

if (field === "StratusFormsRepeatable") {
            var repeatableArray = formData[field];
            var repeatNum = 0;
            for (var index in repeatableArray) {
                if (repeatableArray[index].StratusFormsParent != "undefined") {
                    $().StratusFormsRepeat(repeatableArray[index].StratusFormsParent);
                }
                var thisRepeatableForm = $(form).find("#" + repeatableArray[index].ID);
                PopulateFormData(thisRepeatableForm, repeatableArray[index],{},repeatNum);
                repeatNum++;
                if (typeof repeatableArray[index].StratusFormsParent === "undefined" ) {
                            repeatNum = 1;
                }
            }
        }

Note the 5th line of that code:

    if (repeatableArray[index].StratusFormsParent != "undefined") {

Note that without any typeof operator we are comparing to the string "undefined".

The fix of resetting repeatNum to 1 if the parent is undefined can more efficiently (and without that error) be accomplished like this:

        if (field === "StratusFormsRepeatable") {
            var repeatableArray = formData[field];
            var repeatNum = 0;
            for (var index in repeatableArray) {

                if (repeatableArray[index].StratusFormsParent != undefined) {
                    $().StratusFormsRepeat(repeatableArray[index].StratusFormsParent);
                } else {
                    repeatNum = 0; // new repeatable, start over
                }
                var thisRepeatableForm = $(form).find("#" + repeatableArray[index].ID);
                PopulateFormData(thisRepeatableForm, repeatableArray[index],{},repeatNum);
                repeatNum++;
            }
        }

plbowers avatar Mar 05 '19 22:03 plbowers