0

I am working on a sharepoint 2013 on-premises edit aspx form. now i have the following checkbox:-

<span title="Yes" class="ms-RadioText">
<input id="UpdateOrder_0e0052d6-9924-4774-b50d-d7ef364d744a_MultiChoiceOption_0" required="" type="checkbox">
<label for="UpdateOrder_0e0052d6-9924-4774-b50d-d7ef364d744a_MultiChoiceOption_0">Yes</label>
</span>

enter image description here

Where i want under certain conditions to set this checkbox as required, so users can not submit the list form unless they check this checkbox. so i wrote the following javascript, inside my Edit form's code snippet web part:-

<script>
var orderstatus0 = $('select[id^="OrderStatus_"]').val();
if (orderstatus0 == "Invoiced")
    {

        $('input[id^="UpdateOrder_"]').required;
        var x = document.getElementById('UpdateOrder_0e0052d6-9924-4774-b50d-d7ef364d744a_MultiChoiceOption_0').required;
        document.getElementById('UpdateOrder_0e0052d6-9924-4774-b50d-d7ef364d744a_MultiChoiceOption_0').required= true;
        alert(x);                               
    }
</script>

but currently no validation will be applied, even inside the alert i was excepting to get true, but i am getting false.. so can anyone advice on this please? Thanks

1

Since you are validating on Submit button, I would suggest you user SharePoint PreSaveAction functionality.

function PreSaveAction() {   

 //your all validation
 //if return true then only form will get submitted 

 }

Read this example, it will help you on its usage.

  • thanks for the reply, actually i have not used this function before,, now i added this function inside my Edit form using a code snippet.,, but seems this function will not get fired when i submit my edit form.. now i am using the built-in Edit form... – john Gu Jul 2 '18 at 17:58
1

There is a really nice way to do this in SharePoint itself using List Validation Settings. You may refer to this link, but I'll try to demonstrate your specific needs:

http://info.summit7systems.com/blog/how-to-conditionally-require-data-in-sharepoint-columns?success=true

What you want to do is only make the checkbox required if the Order Status equals "Invoiced". To do this:

  1. Make the list column Update Order not required.
  2. In SharePoint, go to the List Settings, and find Validation Settings.
  3. Craft your Validation formula as follows:

=IF([Order Status] = "Invoiced", IF([Update Order] <> "No", TRUE, FALSE), TRUE)

If that doesn't work, it's possible the Checkbox is returning TRUE and FALSE instead of Yes and No (this happens with SharePoint options sometimes). If that's the case, then your formula will be:

=IF([Order Status] = "Invoiced", IF([Update Order] <> FALSE, TRUE, FALSE), TRUE)

In this way, the validation will succeed in every case except where Order Status = "Invoiced" and the Update Order checkbox is NOT checked.

Please let me know if this helps.

  • I already thought of this approach,, but the problem in my case, i have already defined the following formula =IF(Status="Invoiced",IF([Customer Invoiced Date]<>"",TRUE,FALSE),TRUE)=IF(Status="Commission Paid",IF([Commission Paid Date]<>"",TRUE,FALSE),TRUE) to do other validations.. and seems the list validation is hard to maintain + i can only have one error message for all the validations... so i was asking about doing so using JavaScript to have more flexible approach compared to using the list validation.. – john Gu Jul 2 '18 at 20:55
  • Ahh, I see your dilemma. You could use clever AND's and OR's all day in your validation, but at the end of the day it's unwieldy and (to my knowledge) there is no way to get around the single validation error message. – C. Dennett Jul 2 '18 at 20:58
  • and i think list validation does not support check-boxes.. as for all the Choice columns which allow multiple selections (rendered as check-boxes), they are not listed inside the List Validation Insert Column: list.. – john Gu Jul 2 '18 at 21:05

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.