Page 1 of 1

Clear subform

Posted: Tue Aug 13, 2019 4:02 am
by HeshanKaru1994
Imagine you have 5 different subforms and you need to clear them depending on the scenario

If process A is selected only 1 subform need to be cleared.
If process B is selected all the subforms need to be cleared.

Re: Clear subform

Posted: Tue Aug 13, 2019 9:12 am
by avanzyl
Hi HeshanKaru1994,

Have you tried using the following javascript in the dynaform?

For example, to reset all fields in a Dynaform to their original values:
$("form")[0].reset()

Re: Clear subform

Posted: Tue Aug 13, 2019 8:36 pm
by amosbatto
Similar to what avanzyl recommends, you can use this code to reset the subform to its orginal values with this JavaScript:
$("#1234567890abcdef1234567890abcdef")[0].reset();
Where 1234567890abcdef1234567890abcdef is the ID of the subform.

Another way is to use this code:
$("#1234567890abcdef1234567890abcdef").find("input, textarea, select").val("");

Re: Clear subform

Posted: Tue Aug 13, 2019 10:55 pm
by HeshanKaru1994
Its not working since all those subforms are used inside a single dynaform

Re: Clear subform

Posted: Tue Aug 13, 2019 10:57 pm
by HeshanKaru1994
And get this error when reset function is used
subform.PNG
subform.PNG (9.13 KiB) Viewed 4681 times

Re: Clear subform

Posted: Wed Aug 14, 2019 3:42 am
by avanzyl
Just make sure that you do in fact have the function written correctly. It looks like you dont have "()" at the end of reset like this:

....reset()

Re: Clear subform

Posted: Wed Aug 14, 2019 7:00 am
by HeshanKaru1994
Thank you for your reply but its not working with the parentheses as well

Re: Clear subform

Posted: Wed Aug 14, 2019 7:20 am
by avanzyl
You get the same error using this?

$("#1234567890abcdef1234567890abcdef").find("input, textarea, select").val("");

Where 1234567890abcdef1234567890abcdef is the subform ID