0

I currently have a PreSaveAction function that I was given. It currently looks at the people picker field (Reviewer 2) to make sure it is filled before allowing the form to be saved. Is there a way to change it to look at the choice field (Rev2 Required) instead? Here's my script:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
function PreSaveAction(){
    //these look for the display name values in the associated people pickers
    var rev2 = $("input[Title='Reviewer 2']").attr("aria-label");

    if(rev2){
        return true;
    }
    else{
        alert("You must select a person as Reviewer 2. Please refer to the Approval and Payment of Invoices policy for guidelines.");
        return false;
    }
}
</script>
3
  • This is not a SharePoint question but a jQuery lesson 1 question api.jquery.com/category/selectors Commented Mar 21, 2017 at 14:38
  • Can you check this for me? Something doesn't seem right. <script type="text/javascript"> function PreSaveAction(){ //these look for the display name values in the choice field var choiceFieldValue = $("select[title$='ChoiceFieldName']").val(); if(choiceFieldValue){ return true; } else{ alert("Does this invoice require a second reviewer? If so, please refer to the Approval and Payment of Invoices policy for guidelines."); return false; } } </script>
    – cbbrown
    Commented Mar 21, 2017 at 17:22
  • No, code in comments is unreadable. As I said your issue is most likely jQuery selectors you don't master.. Open F12 Console (learn to use the console instead of alert) and test your selectors there first. You can't run when you never learned to walk Commented Mar 22, 2017 at 12:27

1 Answer 1

1

You've to use Select for Choice field.

var choiceFieldValue =  $("select[title$='ChoiceFieldName']").val();

Then check the variable according to your requirement.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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