controller.onLoadData

Reading Time: 1 minute

It is fired when the controller gets its selectable data from the database. Good for filter 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 controller are linked with more than one fields.

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;
};

There are no comments yet.
Subscribe to our newsletter
or Contact us!
Please note that by subscribing to our newsletter, you agree to receive regular email messages from VCC Live® about service related news and updates. By subscribing to our newsletter, you also agree that VCC Live® will use your data in accordance with the applicable Privacy Policy until you unsubscribe from the newsletter.