Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Required Radio Buttons not validated

Avatar

Former Community Member
When I Submit(email)a form required Radio buttons are not validated (form is submitted whether checked or not). Is there something I am missing? How do I have required Radio buttons validated correctly.
6 Replies

Avatar

Former Community Member
Yes it's true. When you have a
exclusion group of radio-buttons you cannot use the
required attribute because the validation never happens.



There are some solutions:




1) Design the form in order that always it begins with a selected option.




2) Validate the field manually using a custom submit button.




//Getting the exclusion group value


var val = xfa.resolveNode("Form1.Page1.exclGroup").rawValue;




if(val != ""){




//If validation is OK then we submit the documnet using for example the
event.target.submitForm expresion.



   app.alert("Validation is OK. Submiting the document...",2,0,"Validation OK");



}else{





   app.alert("You must choose some option",0,0,"Validation Error");



}





I hope this helps you,

Dan

Avatar

Former Community Member
When you have a exclusion group of radio-buttons you cannot use the required attribute because the validation never happens.



Is this a bug?

Avatar

Former Community Member
No, it is not exactly a bug.<br /><br />I mention Stefan's explanation:<br /><hr><br /><i>[...] exclusion groups, even they contain fields and have similar attributes, aren't actually fields: They have different "class names" such as <field> and <exclGroup>.</i><br /><hr><br /><br />Therefore, if the exclusion groups aren't fields it is imposible to set it as required.<br /><br /><b>Good luck</b>,<br />Dan

Avatar

Former Community Member
Seems strange. If I make them required and select "highlight required fields" when filling out the form in Reader, the radio buttons (exclusion group) is highlighted. It is only on the Submit when all of a sudden the required property seems to disappear. To me, that's a bug.

Avatar

Former Community Member
Actually, in this case, it is a bug. Even though exclusion groups are "fields" per se, they still have some of the same attributes and they're the ones that store the value of the selected radio button within their group. Therefore, one should be able to set an exclusion group (i.e. radio button group) as "required".



Unfortunately, there's a bug in Acrobat which ignores the "required" attribute of exclusion groups upon data submission. This bug has been reported and will hopefully be fixed in a future release.



For the time being, you can use Danmaster's solution or you can use another solution which uses two buttons: The first is the actual submit button (either email or HTTP) and is invisible. Let's name it "EmailSubmitButton". The second is a regular, visible button which has script in its Click event which will verify that a value has been specified for the exclusion group. If a value has been specified, the script then executes the invisible submit button's Click event which will then trigger the form's data to be submitted. Otherwise, the script can show an error message.



The following script is an example of what you would put on the regular button's Click event (in JavaScript):



if (RadioButtonGroup.rawValue != null) // user picked a radio button

EmailSubmitButton.execEvent("click"); // submit data

else

app.alert("Please pick an option in the list.");


Note that this technique is also very useful for validating the form prior to submitting or printing it if you have to do more complex validations aside from setting some fields as "required".



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks Stephan. I'm familiar with the dual Submit button approach and have used it many times. Thanks also for confirming this as a bug. I would be scratching my head if the LC Designer and/or Acrobat dev teams felt otherwise.