1

I am working on a team site inside my sharepoint on-premises 2013. now i have the following site column of type choice:-

enter image description here

now i want to make this site column required under certain scenarios, so i decide to force this column to be Required using javascript. now this site column will be rendered as following inside our edit forms:-

<input id="OrderLiveOrder_0e0052d6-9924-4774-b50d-d7ef364d744a_MultiChoiceOption_0" type="checkbox">

so inside my JavaScript which i am referencing inside my Edit form, i tried the following 2 approaches:-

Using prop

$('input[id^="OrderLiveOrder_"]').prop("required", true);

then using attr

$('input[id^="OrderLiveOrder_"]').attr("required", true);

now those will modify the field's markup to be as follow, by adding the required="required" attribute:-

<input id="OrderLiveOrder_0e0052d6-9924-4774-b50d-d7ef364d744a_MultiChoiceOption_0" type="checkbox" required="required">

but this will not prevent the users from submitting the checkbox, if they leave it uncheck.. so can anyone advice how i can force my Choice site column to be conditionally required inside my edit form?? Thanks

1

Are you using your own custom form?

Check your Save button to see if it will call any validation code when clicking it.

When we save an item using OOB Save button from the SharePoint UI (NewForm.aspx, EditForm.aspx), there is built-in script (PreSaveItem function) to validate the entries.

A example of the OOB Save button element:

<input type="button" name="ctl00$ctl40$g_7b31e59b_9242_4af3_b49e_78224c2fdee7$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem" value="Save" onclick="if (!PreSaveItem()) return false;if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ1')) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl40$g_7b31e59b_9242_4af3_b49e_78224c2fdee7$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))" id="ctl00_ctl40_g_7b31e59b_9242_4af3_b49e_78224c2fdee7_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem" accesskey="O" class="ms-ButtonHeightWidth" target="_self">

If PreSaveItem() returns true, then the item will be saved.

If you are using the custom form to save, it will not validate the required entries by default as there is no any script for that.

You need to add validation code.

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.