2

Just wondering if there is a way to check whether a People Picker field is empty using the function "PreSaveAction". I'm able to do it with other types of field (text field, dropdown field) but with People Picker field is not working with the same logic.

The example below is the way that I'm doing with text field.

function PreSaveAction() 
{

if(getField('field1').value == "" && getField('field2').value == "" && getField('field3').value == "" && getField('field4).value == "" && getField('field5').value == "" && getField('field6').value == "" && getField('field7').value == "" && getField('Produção - Emitente').value == "")
{
alert('Please, fill the fields bla bla bla bla..."');
    return false;

}else{
    return true;
    }
}

Thanks

2

The People Picker creates a div for it when it is rendered on the page. Here is some code I use to see if the People Picker is empty and get the user account name if it is not:

function selectedUser() {
    var userAccount = "";
    var peoplePicker = $("div[title$='People Picker']");
    var peoplePickerValue = peoplePicker[0].innerHTML;

    if (peoplePickerValue != "") {
        peoplePicker = peoplePicker[0].firstChild.id;
        userAccount = peoplePicker.substr(4, peoplePicker.length);
    }
    return userAccount;
}

It is a little tricky, but you can get the values through jQuery. Hope this helps!

0

Using SPUtility you can check if a people picker field has value by checking

SPUtility.GetSPFieldByInternalName(peoplePickerInternalFieldName).GetValue().length>=0

The length property denotes how many users are selected in the people picker field.

You can use the same condition for multiple choice fields too.(Checkboxes).

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.