StratusForms icon indicating copy to clipboard operation
StratusForms copied to clipboard

PopulateFormData() does not respect $(form) on StratusFormRepeatable's

Open plbowers opened this issue 5 years ago • 0 comments

The first argument of PopulateFormData() is form and as a jquery selector it is supposed to limit which fields are being populated (or at least that's how I've understood it based on how it is called through $(form).StratusFormsInitialize() and LoadFormFields(form, ...) and how it works with all other fields except the exception below).

In other words, if I call $(form).StratusFormsInitialize() I expect ONLY fields that are within $(form) to be initialized.

If there is a StratusFormsRepeatable section that is in the data but not within $(form) then it is initialized regardless.

My fix added these lines:

if ((repeatableArray[index].StratusFormsParent !== undefined && !$(form).find("#" + repeatableArray[index].StratusFormsParent).length) || (!repeatableArray[index].StratusFormsParent && !$(form).find("#" + repeatableArray[index].ID).length)) { console.log('DBG: PFD: Jumping ship early'); continue; }

They should be placed between these 2 lines on 714-715:

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

There may be a more elegant way (I note that I have lost the theoretical potential of repeatables within repeatables), but this is at least one way to fix it.

plbowers avatar Oct 26 '19 21:10 plbowers