Posts tonen met het label People Picker. Alle posts tonen
Posts tonen met het label People Picker. Alle posts tonen

zondag 11 januari 2015

Check or Get People Picker value.


New function to check if a people picker field is empty or to get the value of a people picker field.
Functions that may be usefull to use in presave actions when editing or creating new list items. 

The function IsPeoplePickerEmpty must be called with a parameter that contains the title of your field. Or with the value of the text that stands on the left side of your people picker field. 

The function  GetPeoplePickerValue must be called with a parameter that contains the title of your field. Or with the value of the text that stands on the left side of your people picker field. It returns a string containing the key of your people picker field. This is the domain and userid of the inserted value. 

Remark. The GetPeoploePickerValue only works with a single user People Picker field. 

 
function IsPeoplePickerEmpty( titel )
{
  if (( $('nobr:contains("'+ titel +'")').closest("td").next("td").find('input')[1].value  == " ") || ( $('nobr:contains("'+ titel +'")').closest("td").next("td").find('input')[1].value  == "") )
         return true;
  else
         return false;
}
function GetPeoplePickerValue(titel)
{
    var result = "";
        if (!IsPeoplePickerEmpty(titel))
        {
                result = $('nobr:contains("'+ titel +'")').closest("td").next("td").find('input')[1].value;
                result = result.substring(result.indexOf("key=") + 5 );
                result = result.substring(0,result.indexOf("'"));
        }
    return result;
}

Set a PeoplePicker Field without a GUID !


A new function that lot's of people may help if they want to set a value of a People Picker field. 
There are examples to find on the internet how you may do it by using the GUID of the field. This because the People Picker field is made of different html parts. You can't set a value in the field directly by calling his Title property like most of the other SharePoint Fields.
But next function by calling the label of the field (the text you have giving on the screen), and a value (Full name of a person or the userid of a person)


Enjoy the new function !! 

Remark, the function only works for setting one value to the people picker field. 
test
// call the new function Set PeoplePicker.
//
SetPeoplePicker (title, userid);

function SetPeoplePicker(My_Title, userid)
{
        try{
                 var ppID = $($('nobr:contains("' + My_Title + '")').closest("td").next("td").find('div')[0]).attr('id');
                 var ppID_userfield = ppID.substring(0,ppID.indexOf("_upLevelDiv"));
                 var a_ppID = ppID_userfield.split('_');
                 var a_ppID_Length = a_ppID.length;
                 var ppID_userfield2 = a_ppID[0] + '$' +  a_ppID[1] + '$' +  a_ppID[2] ;
                 for ( i = 3; i < a_ppID_Length - 4; i++)
                 {
                       ppID_userfield2 = ppID_userfield2 + '_' + a_ppID[i];
                 }
                 ppID_userfield2 = ppID_userfield2 + '$' +   a_ppID[a_ppID_Length - 4] + '$' +   a_ppID[a_ppID_Length - 3] + '$' +   a_ppID[a_ppID_Length - 2] + '$' +   a_ppID[a_ppID_Length - 1] ;
        
                $('#' + ppID ).text(userid);
                //recognize the people picker driver name
                if(!ValidatePickerControl(ppID_userfield )){
                        ShowValidationError();
                        return false;
                }
                var arg=getUplevel(ppID_userfield );
                var ctx = ppID_userfield ;
                EntityEditorSetWaitCursor(ctx);
                WebForm_DoCallback(ppID_userfield2 ,arg,EntityEditorHandleCheckNameResult,ctx,EntityEditorHandleCheckNameError,true);
        }catch(err){
                $('#' + ppID).text("");
        }
}


donderdag 28 november 2013

Set Focus on a sharepoint Field in scripting

To setting the focus of an input field in jquery, it was simple. But when you have a peoplepicker field
you think that you also are dealing with an input field, but less is true.
A sharepoint People Picker field isn't that easy made.
But we won't be a developer, if we could make a function that put's the focus also 
on a people picker field.
Below you find my function. It can be extended with other fields if necessary. 
You call it not by using the GUID, but by using the display name. Which is more flexible and easier, 
because you don't need to search for the GUID in the source code. 
 
You can call it by the next function. You only need the Field Display Name and the Type of field. 
The type can be at this moment, an Input field, a People Picker, or a  Select field. 

This you can use by example when you want to check values in the PreSaveAction function and 
you want to put the focus on a field that has to be changed.  
 
Have fun with it... and if you need an extention, don't hesitate to ask... 

 
function FirstfocusExtended(veldnaam, type)
{
                switch (type.toLowerCase())
                {
                               case "input" :
                                               $(":input[title='" + veldnaam + "']").focus();
                                               break;
                               case "peoplepicker" :
                                               $("nobr:contains('" + veldnaam + "')").closest("td").next("td").find("div").focus();
                                               break;
                               case "select" :
                                               $(":select[title='" + veldnaam + "']").focus();
                                               break;
                               default :
                                               break;
                }
}

woensdag 9 oktober 2013

Disable a PeoplePicker Field without knowing the ID of your Sharepoint Field


I'm starting to write my own sharepoint helperclass with functions 
that can be called without knowing the ID's of the Sharepoint Fields, 
but by using the field Display Names. 

This function is to Disable or Enable a Sharepoint PeoplePicker Field.


// call the function
// DisablePeoplePicker ("DISPLAYNAME", True) to disable the field
// DisablePeoplePicker ("DISPLAYNAME", False) to enable the field
  
function DisablePeoplePicker( titel, b_disable)
{
    $('nobr:contains("'+titel+'")').closest("td").next("td").find("div").attr("contentEditable",false);
    if (b_disable)
    {
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("div").css("backgroundColor","silver");
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("img").hide();
    }
    else
    {
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("div").css("backgroundColor","white");
        $('nobr:contains("'+titel+'")').closest("td").next("td").find("img").show();
    }
}