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

Problem with reset button

Avatar

Level 9

Hello All,

I have a form which has several fields. There is a reset button at the top of the Page -1 of the form which should clear/rest  the form. But I have several checkboxes, out of which if some clicked few text fields / drop downs associated with it becomes mandatory. Suppose one clicks Checkbox -1 and the field TextField -1 associated with becomes mandatory.If the user clicks the reset button after clicking the checkbox (which makes the field mandatory) then though the checkbox is unchecked the field remains as  mandatory. How to get over it with ? I have placed the script in the change event as well as in the click event of the text box as there are conditions to met (Suppose there are 3 check boxes associated with a text field and the field becomes mandatory if one of them is clicked) Any help would be greatly appreciated.

Thanks.

Bibhu.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Bibhu,

It is difficult to say without seeing the form, but a couple of things:

  • Try testing against null as well.
  • Check the binding on the checkbox on page1 that it has binding of '1' and '0'.
  • Double check the object reference for the checkbox on page1, eg is it in another subform.
  • Use the JavaScript Console (Control+J when previewing) to see are there any errors when exiting the textfield.

I would agree with the script being in the exit event.

I have an aversion to naming design pages with a capital 'P', as this is used for Master Pages, so I would generally use page1, ... page5. This isn't the problem here, just a comment.

Good luck,

Niall

View solution in original post

7 Replies

Avatar

Level 10

Hi Bibhu,

How about you add a line for each checkbox AFTER the reset command:

// reset the form (including checkboxes)

xfa.host.resetData();

// now that checkboxes are unchecked, fire script again

checkbox1.execEvent("click");

checkbox2.execEvent("click");

checkbox3.execEvent("click");

...

This is on the basis that the script to make the fields mandatory is in the click event of the checkboxes.

Good luck,

Niall

Avatar

Level 9

Hello Niall,

Instead of the click event I have added change event . Now it seems to be working.

Thanks.

Bibhu.

Avatar

Level 10

Hi Bibhu,

Glad its working.

For the checkbox script, I would be inclined to go with the click event.

Niall

Avatar

Level 9

Hello Niall,

I have a textfield(in Page-5) which has an associated readonly checkbox in Page -1 . If someone enters some value in the text field then the checkbox must be checked and vice versa.I have tried the script in exit as well as in the change event of the text field.But the else part does not seem to work.

How to rectify that ?

form1.Page5.SpecialInstructions::exit - (JavaScript, client)
if(SpecialInstructions.rawValue != "")
{
   form1.Page1.SpecialInstructions.rawValue = 1;
}
else
{
   form1.Page1.SpecialInstructions.rawValue = 0;
}  

Thanks.

Bibhu.

Avatar

Correct answer by
Level 10

Hi Bibhu,

It is difficult to say without seeing the form, but a couple of things:

  • Try testing against null as well.
  • Check the binding on the checkbox on page1 that it has binding of '1' and '0'.
  • Double check the object reference for the checkbox on page1, eg is it in another subform.
  • Use the JavaScript Console (Control+J when previewing) to see are there any errors when exiting the textfield.

I would agree with the script being in the exit event.

I have an aversion to naming design pages with a capital 'P', as this is used for Master Pages, so I would generally use page1, ... page5. This isn't the problem here, just a comment.

Good luck,

Niall

Avatar

Level 9

Hello Niall,

I tried on Null, then it worked. But I am little confused, what's the difference between Null and "" ?

Thanks.

Bibhu.

Avatar

Level 10

Hi Bibhu,

null tests for empty/no value, whereas "" is still a string of zero length. I find testing for null is more robust.

Maybe someone else will have a more technical explanation.

Good luck,

Niall