Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > JavaScript API > SearchController object > Methods

JavaScriptAPI: SearchController object > addField()

Scroll Prev Next More

 

Deprecated

SearchController object methods are deprecated, we recommend using Search API instead.

 

Adds a field to the search panel. Then calls the callback function, passing the SearchField object of an added field as the argument. In the callback function, you can use all the functionality available for the SearchField object.

Syntax

srch.addField(fieldName, callback(field))

Arguments

fieldName

the name of the field. Example: 'Make'.

callback(field)

a call to a callback function. field is the SearchField object of an added field. This argument may be omitted.

Return value

No return value.

Example 1

Add the Make field to the search panel using the JavaScript OnLoad event:

 

var srch = pageObj.getSearchController();
srch.addField('Make');

Example 2

Add the Price field to the search panel and set search parameters using the JavaScript OnLoad event:

 

var srch = pageObj.getSearchController();
 
srch.addField('Price', function( field ) {
   field.getControl().setValue("20000");
   field.setOption(Runner.search.options.LESS_THAN);
});

Example 3

Add five Make fields to the search panel using the JavaScript OnLoad event:

 

var srch = pageObj.getSearchController();
var field = srch.getSearchFields('Make');
var count = field.length;
 
for (i=count; i<5; i++)
   srch.addField('Make');

See also:

JavaScript API: Control object > setValue()

JavaScript API: SearchField object > setOption()

JavaScript API: SearchField object

About Search API

Events: JavaScript OnLoad

JavaScript API: SearchController object (deprecated)

JavaScript API