Friday, 4 July 2014

Jquery selectors - Wildcards for Finding Sharepoint fields with Internal Names in newform,editform and Displayform.

Hi All,
 Today we will see something related to jQuery. This was helpful when i tried to get the internal names of the columns in the newform, editforms.

Getting the controls in the forms using the label names would be inconsistent, as the labels could be changed frequently causing our code to break. So we have to query the fields using "id" of that element.

For example, if there is a control named "Project Name", its id could be "ProjectName_12h1278hk9kkhasfkcyh9"..

That is, "Internal Name of the column("ProjectName) + some junk"

These wild card selectors were very useful in finding the controls. This would be of a great help when u come across these sort of situations.


If you want to select elements with an id which ends with a given string :
$("[id$='myValue']")


If you want to select elements with an id which starts with a given string :
$("[id^='txtTitle']")


If you want to select elements which id contains a given string  :
$("[id*='txtTitle']")


If you want to select elements which id is not a given string  :
$("[id!='myValue']")
(it also matches the elements that don't have the specified attribute)


If you want to select elements which id contains a given word, delimited by spaces :
$("[id~='myValue']")


If you want to select elements which id is equal to a given string or starting with that string followed by a hyphen:
$("[id|='myValue']")


Have a good day....