1

How to make a field required on the edit form. It does not appear on the New Form. I can't set it as required at the site column level because the system will not save the New form without that field completed.

I took this PreSaveAction script from another form I have used it with and tried to modify to fix my issue. I installed it as a script editor web part and when I went to the edit page, it triggers the alert, but won't save when I actually fill in the field.

function PreSaveAction(){

var Approver Email=  $("select[title$='login']").val();


if(Approver Email!= "" && Approver Email !=undefined ){
    return true;
}
else{
    alert("Please insert your email");
    return false;
}

}

  • Your variable name should not have a space. It should be ApproverEmail – Ahmad Zia Dec 8 '18 at 4:13
0

Suppose the login field is a People or Group field. Get the value of it in PreSaveAction like that

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
var dispTitle = "login";      
var pickerDiv = $("[id$='ClientPeoplePicker'][title='" + dispTitle + "']");      
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv.attr("id")];
var userInfo = peoplePicker.GetAllUserInfo();
if(userInfo.length > 0){
    console.log(userInfo[0].IsResolved) 

    if(userInfo[0].IsResolved){
        return true;
    }
    else{
        alert("Please insert your email");
        return false;
    }
}
else{
    alert("Please insert your email");
    return false;
}
</script>
  • It's not working for some reason on my end Ahmad. – andy Dec 12 '18 at 14:58
  • Do you see any javascript error in console window? – Ahmad Zia Dec 13 '18 at 0:47
  • no because I am using script editor which doesn't show any error – andy Dec 14 '18 at 14:24

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.