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;
                }
}

dinsdag 26 november 2013

Set a check or more checkboxes of a choice field selected.


A nice new function is created today for my colleague
If you want to check a checkbox of a checkbox field or a multi choice field, 
you can use the next function. 
You can call it by not knowing the GUID of the checkbox you want to select. But you can call it with 
the Display Name (Title) of your field. 
If it only one checkbox, you call it like this :
SetChoiceFieldValue ("YOUR TITLE", 1, true);
 
If you have a choice field with more options, you can select specific entries 
by setting the index to the checkbox you want to select. 
You can use the same function also to uncheck the field. You only have to set the last param to false. 

It's a nice jquery function that makes your scripting more flexible. 


 
function SetChoiceFieldValue(titel, index, b_checked)
{
        var TD = $('nobr:contains("'+ titel + '")').closest("td").next("td").find('input');
        if (index <= TD.length + 1)
        {
                TD[index-1].checked = b_checked;
        }
}