controller.onLoadData
It is fired when the controller gets its selectable data from the database. Good for filtering the allowed values. Important: the controller loads its data on page load and when its CONTROLLER_OBJECT.rebuild function called. (It is not called on CONTROLLER_OBJECT.refresh, and when the user change the selected tab.) Some controllers are linked with more than one field.
Parameters
Name | Type | Description |
---|---|---|
data | {Array of FIELD_VALUE_OBJECT} | the values of the actual field |
field | {String} | the name of the actual field. |
Returns
Type | Comment |
---|---|
Array | the modified data. If it is null, this field will be skipped. |
Example
The description of the values of the mobile_phone field contains the export_value of a manufacturer. The user has selected the manufacturer before, we want to show only the appropriate phones.
$('page', 'mobile_phones').onLoadData = function(data) {
var manufacturer = vcc.getFieldValue('manufacturer');
if (!manufacturer) {
// if there is no selected manufacturer,
// let be there no selectable phones
return [];
}
// filter the data array
return data.filter(function(phone) {
return phone.description = manufacturer.export_value;
});
};
Example
The same as above, but do not hide the the inappropriate values, just make them disabled.
$('page', 'mobile_phones').onLoadData = function(data) {
var manufacturer = vcc.getSelected('manufacturer');
if (!manufacturer) {
// if there is no selected manufacturer,
// let be all phones selectable
return data;
}
// apply a change for every item in the array
data.forEach(function(phone) {
phone.disabled = (phone.description !== manufacturer.export_value);
});
return data;
};
Comments
Can’t find what you need? Use the comment section below to connect with others, get answers from our experts, or share your ideas with us.
There are no comments yet.