Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Re; Reset a form based on users checkbox selection

Avatar

Level 3

I have a form with four check boxes.

 

Water, Soda, Ice, Plain

If the users toggles between them, I need the form to reset because they selected another checkbox. I would like the "Completed" button to clear all fields and subforms.

 

Thank you in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi there,

 

First, do you have any experience with the software or JavaScript?

By the look of it, you seem to be working with radio buttons instead of check boxes. Radio buttons is a list of items which the user can only select 1 at a time. This is only technical question to start with, no intention to offense you.

 

To reset a form, you can always use the method xfa.host.resetData(); which will reset all fields to default value.

This method will also remove the user's new selection. To be able to reset only parts of the form you may want to add a subform's somExpression as parameter to reset only that part of the form. Let's say you want to reset multiple subforms at a time that does not contain the 4 main checkboxes you could use the following:

xfa.host.resetData(subFormWater.somExpression + "," + subFormSoda.somExpression + "," +  subFormIce.somExpression + "," + subFormPlain.somExpression);

the name preceding the "somExpression" should be the correct reference syntax to access the appropriate subform that relates to the 4 main options.

resetData function can only have 1 parameter at time, but you can concatenate all the parameters with commas into 1 string which will act as if you inserted multiple parameters.

 

In case that all the subforms are all in 1 subform, you can simply write one subform's somExpression.

xfa.host.resetData(subFormData.somExpression);

 

I hope this will help.

Let me know if you have any questions.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi there,

 

First, do you have any experience with the software or JavaScript?

By the look of it, you seem to be working with radio buttons instead of check boxes. Radio buttons is a list of items which the user can only select 1 at a time. This is only technical question to start with, no intention to offense you.

 

To reset a form, you can always use the method xfa.host.resetData(); which will reset all fields to default value.

This method will also remove the user's new selection. To be able to reset only parts of the form you may want to add a subform's somExpression as parameter to reset only that part of the form. Let's say you want to reset multiple subforms at a time that does not contain the 4 main checkboxes you could use the following:

xfa.host.resetData(subFormWater.somExpression + "," + subFormSoda.somExpression + "," +  subFormIce.somExpression + "," + subFormPlain.somExpression);

the name preceding the "somExpression" should be the correct reference syntax to access the appropriate subform that relates to the 4 main options.

resetData function can only have 1 parameter at time, but you can concatenate all the parameters with commas into 1 string which will act as if you inserted multiple parameters.

 

In case that all the subforms are all in 1 subform, you can simply write one subform's somExpression.

xfa.host.resetData(subFormData.somExpression);

 

I hope this will help.

Let me know if you have any questions.

Avatar

Level 3

Thank you for responding.

I am not a JavaScript guru, If the user makes a selection in the "Canopy" dropdown and changes their mind and goes back and selects something else in the "Canopy" dropdown that subform resets. The current reset "xfa.host.resetData();" only resets the fields in the Canopy subform. (current subform). I would like all subforms/fields in the form to reset.

 

Thank you in advance,

Avatar

Level 10
Well then you might want to specify inside the resetData function which subform(s) you want to reset like I showed previously. Ensure that all subforms you insert are the ones you want to reset only, which should exclude any subform containing the canopy subform.