1

I'm struggling to find some Javascript to allow the following;

I would like to make a number of columns required, however these columns will be 'hide/show' based on the previous answer. That bit i have working fine.

The problem is; this only works when I leave all columns as optional, but I would like to make them all required. When they are hidden I would like them to change to optional. Is this possible? Many thanks.

0

have you tried using the Validation settings option? , below is an example maybe it can help in your case.

in this example i have three fields, Name (text) , US Citizen (Choice) and US Address (text).

in case US Citizen = Yes, US Address field should be mandatory.

Navigate to list settings then Validation settings

in the Formula section in my case i use the below formula:

=IF([US Citizen]="Yes",IF([US Address]<>"",TRUE,FALSE),TRUE) 



Click OK and test , US address field will be required only when the US Citizen = Yes

enter image description here



enter image description here

| improve this answer | |
  • I had not tried this but I have now, and is so close to getting me to where i wanted. so thank you. – Katie Hibberd Feb 27 '18 at 21:33
  • you're welcome, glad to help @KatieHibberd – A.Saéed Feb 28 '18 at 11:02
  • I have set up this validation, in my Javasript I hide/show columns depending on the answer to the first question using the change function. When I save an item, and i get my validation error. It also makes all columns now available in the form. Do you know how to prevent this? Many thanks in advance. Katie – Katie Hibberd Mar 5 '18 at 15:02
  • @KatieHibberd please update your question with the script you're using – A.Saéed Mar 6 '18 at 10:28
  • thank you for your reply. I have solved this issue today. I combined ready and change functions in my JS, and it works perfectly now. Thank you for your help. – Katie Hibberd Mar 6 '18 at 16:28
1

No, you can't toggle the Required setting on a field on a per-session basis. If it's required, it's required for everyone.

What you want to do is leave the column as optional and enforce your validation on the client side.

| improve this answer | |
  • Thank you Derek! such a shame because this would be useful for us. At the minute required fields are hidden and the form won't save, but if those questions in another form are shown we would like to force them to provide an answer :-) – Katie Hibberd Feb 27 '18 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.