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

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
scroll top