The following functions cover acquiring and applying values to fields.
sfjs.get(fieldNameOrId);
Remarks
Shortcut alias for the getFieldValue() method, described in detail below.
Example
//Gets string value of the City user profile form field
sfjs.get("up_UserProfileCity");
sfjs.getField(fieldNameOrId);
Returns
Returns the jQuery object for the referenced field.
Example
//Sets myFieldObj variable to the City user profile form field object
var myFieldObj=sfjs.getField("up_UserProfileCity");
sfjs.getFieldValue(fieldNameOrId);
Returns
Returns value of the referenced field regardless of the field type. Possible return values are:
■ A string for single- and multi-line text fields, radio buttons (the selected value, or undefined if no radio button is selected), and checkboxes (the value whether checked or unchecked).
■ An object for multi-select checkboxes. The object contains all options with a value of true or false for each.
■ A string array for drop-down lists. The array comprises all selected options.
■ An empty string for unselected list boxes.
■ The uploaded asset ID for image upload fields, or undefined if the image upload field is empty.
■ The complete contents of HTML Literal fields.
Remarks
Field IDs consist of the field name prefixed by a two-letter abbreviation for the form to which the field belongs, joined together by an underscore. Available abbreviations are:
ab = Address book
ff = Form filling step of Customization
po = Product Options step of Customization
py = Payment step of Checkout
sh = Shipping step of Checkout
sr = Self-registration
up = User profile
Example
//Gets string value of the City user profile form field
sfjs.getFieldValue("up_UserProfileCity");
sfjs.set(fieldNameOrId, value);
Remarks
Shortcut alias for the setFieldValue() method, described in detail below.
Example
//Sets Title customization form field to "High Muckity-Muck"
sfjs.set("ff_Title","High Muckity-Muck");
//Set a multi-select field’s values (not labels)
sfjs.set(“State”, [“MA”, “MN”, “NC”, “TX”, “VT”, “WA”]);
sfjs.setFieldValue(fieldNameOrId, value);
Remarks
Sets the value of a field to something specific. This works on any type of field and triggers the appropriate change actions related to validation, conditional statements, and preview rendering.
■ Checkboxes can be set to checked by providing either the string checked or true or by supplying the configured <value if checked> value.
■ Fields restricted to specific options, such as drop-down lists and radio buttons, will remain unaffected if set to a value that does not match any of the options.
■ Multi-select fields (multi-select list box, multi-select checkbox) accept either a string to set a single value or an array of strings to set multiple values. If no options match the provided value(s), all options will be deselected.
Note that as part of performance enhancements introduced in 9.4.0 the default behavior of this method has been modified so that any fields updated by multiple calls in one frame will suppress redundant previews.
Examples
//Sets Title customization form field to "Supreme Leader"
sfjs.setFieldValue("ff_Title","Supreme Leader");
//Sets State dropdown value to "PR"
sfjs.setFieldValue("ff_State","PR");
sfjs.setMultipleFieldValues(fieldValuesObject);
Remarks
This sets the values of multiple fields in a single API call. If you have to save a lot of fields at once this method can be more efficient than using setFieldValue (or set) for each field.
The same rules that apply to setting a single field using the setFieldValue method above apply to this function, too.
There is no need to call this function specifically to render one preview after all the fields are saved, as that is the default setFieldValue behavior Since version 9.4.0 for fields updated by multiple calls in one frame.
Example
//Sets multiple field values
sfjs.setMultipleFieldValues({
‘ff_City’:’Truth or Consequences’,
’ff_State’: ’NM’,
‘ff_Zip’: ‘87901’
});
sfjs.resetAllFieldToDefaults(optionalFormId);
Parameter
■ optionalFormId—Abbreviation for the step or page form whose fields are to be cleared (optional). For available abbreviations refer to getFieldValue(), above.
Remarks
Setting multiple fields at once internally employs the setFieldValue function so the same rules that apply to setting a single field using that method apply to this function as well. Setting multiple fields at once will only render one preview after all the fields are saved.
Example
//reset all fields to defaults
sfjs.resetAllFieldsToDefaults();
//reset only product options fields to defaults
sfjs.resetAllFieldsToDefaults("po");