Methods
(
source code)
Get the description of the field(s) selected by "formfields"
Returns:
String|Array
Returns the description of the field(s)
Example:
$SP().formfields("Title").description(); // return "This is the description of this field"
$SP().formfields("List of options").description(); // return "", it means no description
(
source code)
Permits to go thru the different fields
Example:
// To print in the console the names of all the fields
$SP().formfields().each(function() {
console.log(this.name()); // -> return the name of the field
console.log(this.isMandatory()); // -> returns TRUE if it's a mandatory field
})
(
source code)
Get the HTML element(s) tied with the field(s) selected by "formfields"
Parameters:
Boolean
usejQuery Optional, Default: true
If jQuery is loaded, then by default the elements will be jQuery object; use FALSE to get the regular DOM elements
Returns:
Array|HTMLElement|jQuery
Null is returned if nothing is found, or the found elements... if jQuery is defined then the HTML elements will be jQueryrize
Example:
$SP().formfields("Title").elem(); // -> returns a HTML INPUT TEXT
$SP().formfields("List of options").elem(); // -> returns a HTML SELECT
(
source code)
formfields(fields, setup)
Retrieve the fields info in the NewForm and in the EditForm
Parameters:
String|Array
fields Optional, Default: ""
A list of fields to get (e.g. "field1,other field,field2" or ["field1","other field","field2"]) and by default we take all fields ... ATTENTION if you have a field with "," then use only the Array as a parameter
Object
setup Optional
Options (see below)
Boolean
setup.mandatory Optional
Set it to 'true' to look for the mandatory fields (the "false" value has no effect)
Boolean
setup.cache Optional, Default: true
By default the form is scanned only once, but you can use {cache:false} to force the form to be rescanned
Returns:
Array
An array of hash with several keys: name, values, elements, type, and tr
Example:
$SP().formfields(); // return all the fields
$SP().formfields({mandatory:true}).each(function() { // return all the mandatory fields
var field = this;
if (field.val().length==0) console.log(field.name()+" is empty!");
});
$SP().formfields("Title,Contact Name,Email").each(function() { // return these three fields
var field = this;
console.log(field.name()+" has these values: "+field.val());
});
// if you have a field with a comma use an Array
$SP().formfields(["Title","Long field, isn't it?","Contact Name","Email"]).each(function() {
var field = this;
console.log(field.name()+" has the description: "+field.description());
});
// returns the fields "Title" and "New & York", and also the mandatory fields
$SP().formfields(["Title", "New & York"],{mandatory:true});
(
source code)
Return the field internalname
Returns:
String|Array
Returns the internalname of the field(s)
Example:
$SP().formfields("Subject").internalname(); // return "Title"
$SP().formfields(["Field Name", "My Field"]).internalname(); // return [ "Field_x0020_Name", "My_x0020_Field" ]
(
source code)
Say if a field is mandatory
Returns:
Boolean|Array
Returns the mandatory status of the field(s)
Example:
$SP().formfields("Title").isMandatory(); // return True or False
$SP().formfields(["Field1", "Field2"]).isMandatory(); // return [ True/False, True/False ]
(
source code)
Return the field name
Returns:
String|Array
Returns the name of the field(s)
Example:
$SP().formfields("Subject").name(); // return "Subject"
$SP().formfields(["Field Name", "My Field"]).name(); // return [ "Field Name", "My Field" ]
(
source code)
Get the TR element(s) tied with the field(s) selected by "formfields"
Returns:
Array|HTMLElement|jQuery
Null is returned if nothing is found, or the TR HTMLElement... or a jQuery object is returned if jQuery exists
Example:
$SP().formfields("Title").row(); // return the TR element that is the parent (= the row)
$SP().formfields("Title").row().hide(); // because we have jQuery we can apply the hide()
(
source code)
Get the type of the field(s) selected by "formfields"
Here is the list of different types returned:
- "text" for the free text field;
- "number" for Number field;
- "currency" for Currency field;
- "text multiple" for the multiple lines of plain text;
- "html multiple" for the multiple lines of text in rich mode;
- "attachments" for the attachments field;
- "lookup" for a lookup field (dropdown);
- "lookup multiple" for a lookup field with multiple selection (two dropdowns with two buttons);
- "content type" for the content type field;
- "boolean" for the yes/no checkbox;
- "date" for a date only field;
- "date time" for a date and time field;
- "choices" for a dropdown selection;
- "choices plus" for a dropdown selection with an input field to enter our own value;
- "choices radio" for the radio buttons selection;
- "choices radio plus" for the radio buttons selection with an input field to enter our own value;
- "choices checkbox" for the checkboxes field for a selection;
- "choices checkbox plus" for the checkboxes field for a selection with an input field to enter our own value;
- "people" for the people picker field;
- "people multiple" for the people picker field with multiple selection;
- "url" for the link/url/picture field.
Returns:
String|Array
Returns the type of the field(s)
Example:
$SP().formfields("Title").type(); // return "text"
$SP().formfields("List of options").type(); // return "choices"
(
source code)
val(value, options, identity, extend)
Set or Get the value(s) for the field(s) selected by "formfields"
Parameters:
String|Array
value Optional, Default: empty
If "str" is specified, then it means we want to set a value, if "str" is not specified then it means we want to get the value
Boolean
identity Optional, Default: false
If set to TRUE then the return values will be a hashmap with "field name" => "field value"
Boolean
extend
In the case of a PeoplePicker under SP2013 it will return the People object
Returns:
String|Array|Object
Return the value of the field(s)
Example:
$SP().formfields("Title").val(); // return "My project"
$SP().formfields("Title").val("My other project");
$SP().formfields("Title").val(); // return "My other project"
// it will set "Choice 1" and "Choice 2" for the "Make your choice" field, and "2012/12/31" for the "Booking Date" field
$SP().formfields("Make your choice,Booking Date").val([ ["Choice 1","Choice 2"], "2012/12/31" ]);
// it will set "My Value" for all the fields
$SP().formfields("Make your choice,Title,Other Field").val("My Value");
// it will return an array; each item represents a field
$SP().formfields("Make your choice,Title,Other Field").val(); // -> [ ["My Value"], "My Value", "Other Field" ]
// for a Link field
$SP().formfields("Link").val(["http://www.dell.com","Dell"]) // -> "Dell" is used as the description of the link, and "http://www.dell.com" as the Web address
// it will return a hashmap
$SP().formfields("Make your choice,Title,Other Field").val({identity:true}); // -> {"Make your choice":["My Value"], "Title":"My Value", "Other Field":"My Value"}
// for SP2013 people picker
$SP().formfields("Manager Name").val({extend:true}); // -> [ { Key="i:0#.w|domain\john_doe", Description="domain\john_doe", DisplayText="Doe, John", ...} ]
$SP().formfields("Manager Name").val(); // -> "Doe, John"