I have 2 fields for weight/capacity in a model. One is for kilos (kgs), the other is for pounds (lbs). As this is part of a managed package, some users will work in kgs, others will work in lbs. I would prefer not to use conditional rendering of the fields (depending on user location) as sometimes they need to work in both.
I’d also prefer not to use formula fields to do the conversions as it would be great if these conversions could be done in real time, rather than with each save operation.
I’ve started on a snippet, but am stuck with getting it to work depending on the field mode. What I’d like to do is:
IF Cargo__kgs__c is in edit mode, then update Cargo__lbs__c (which is in read mode) with the converted lbs value,
otherwise
IF Cargo__lbs__c is in edit mode, then update Cargo__kgs__c (which is in read mode) with the converted kgs value.
is this possible? My hacked-together snippet below…
var field = arguments[0], value = arguments[1];
//runs on the kgs field
$ = skuid.$,
dt = field.metadata.displaytype;
if (field.mode == ‘edit’) {
skuid.ui.fieldRenderers[dt]field.mode;
} else {
skuid.ui.fieldRenderers[dt].read(field,value);
var m = skuid.model.getModel(‘CharterOpParent’);
var row = m.getFirstRow();
//reference the fields by thier API name
var lbs = row.stack__Cargo_lbs__c;
//var kgs = row.stack__Cargo_kgs__c;
//add all the fields together
var convert = function() {
value = (Number(lbs) * 2.2);
skuid.ui.fieldRenderers[field.metadata.displaytype]field.mode;
};
convert();
var listener = new skuid.ui.Field(field.row,field.model,null,{fieldId: ‘stack__Cargo_kgs__c’});
listener.handleChange = function(){
convert();
};
field.model.registerField(listener,‘stack__Cargo_kgs__c’);
}
Question
Custom Field Renderer - one or the other (depending on field mode)
This topic has been closed for replies.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.