UI Page Jelly - Mandatory and Required Attributes doesn't work as expected!

rajalakshmi12
Mega Expert

Hi All,

I woud like to have empty check for my fields in the form using mandatory="true" in the jelly scripting on a UI page, without going in for a customized check on the field.

But the mandatory="true" or required="true" doesn't seem to work on Jelly scripting in UI page. Can anyone please help?

Thanks & Regards,

4 REPLIES 4

divya mishra
Tera Guru

Hi Rajalaxmi,



Could you please try this instead in the client script:



if(gel('ID').value==''){//input the id of the field


alert("fieldname is mandatory is mandatory.");





post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


rajalakshmi12
Mega Expert

Hi Divya,



Yes, I have been using this on my ui pages. But I was wondering why the mandatory="true" is not working.



Thank you.


No some of the javascript   things are obsolete.


just an additional thing if you want to show a field mandatory just add and additional span with value * and color red



post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


HI Rajalakshmi,



It reads like what you've done is made a custom UI page and are doing something like the following to generate a checkbox that is required.


        <g:ui_checkbox mandatory="true" name="my_mandatory_checkbox" >My Mandatory Checkbox</g:ui_checkbox>



Doing this won't make the checkbox element required because the ui_checkbox macro isn't built to accept that attribute. However, this doesn't mean you need to create a new one. If you need this to be set as required you can simply put something similar to this in the client script section of the UI Page record:


        gel('ni.my_mandatory_checkbox').required = true



Notice the "ni." prefix. The reason for this is because the ui_checkbox macro when rendered actually creates two checkbox inputs, one being hidden which is the one that developers would be using to perform actions on; ie gel('my_mandatory_checkbox').value   to get the value.



Be aware that this won't put a red asterisk to show that it is mandatory. But it will stop the form from being submitted if not filled in.