Use field from another model in custom field renderer?

  • 2
  • Question
  • Updated 3 years ago
  • Answered
  • (Edited)
I've got a custom field renderer in a table column that show's a blank input below the current value of the field.  It's working except that it loses focus after entering a few characters in the input.  I found this topic which describes what I'm seeing as well.

https://community.skuid.com/skuid/topics/text_fields_losing_focus_on_their_own_switching_to_browser_quick_buttons

However, I'm not sure if I can implement a solution similar to the one suggested:  use a different model.

Here's the snippet for the custom renderer:

var $ = skuid.$,    params = arguments[0],
    values = arguments[1],
    model = arguments[0].model,
    row = arguments[0].row,
    mode = arguments[0].mode;
    element = arguments[0].element;
// A shortcut function to save some complexity below
function renderField( fieldName){
    var field = new skuid.ui.Field( row, model, null, { fieldId: fieldName, register: true } ),
    value = model.getFieldValue( row, fieldName );
    skuid.ui.fieldRenderers[field.metadata.displaytype][mode]( field, value );
    return field.element;
}
function truncateWithEllipses(text, max) {return text.substr(0,max-1)+(text.length>max?'...':''); }
var oV;
var rowId = row.Id;
var valT;
//only display the first 30 chars of this field
try{
    valT = truncateWithEllipses(values, 30);
} catch(e) {
    valT = values;
}   
//get the original value
try {
    oV = model.originals[rowId].Latest_Update__c;
} catch (e) {
    oV = values;
}
if (mode==='edit'){
    element.append($('<span>').text(oV), renderField('Latest_Update__c');
} else {
    element.append($('<span>').text(valT));
    
}

Is it possible to use a field from a different model (UI only) in a custom renderer?
Photo of Jared Jones

Jared Jones

  • 2,214 Points 2k badge 2x thumb

Posted 3 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
I haven't really processed your code.  But the ui only reference field will be in your model, and as such is availalbe to the API for use in code.  You should explore the model in the console to make sure the data is being loaded.   For example - the target model has to be after the source model in the model definition,  so that the source is loaded and available for the target to process. 
Photo of Jared Jones

Jared Jones

  • 2,214 Points 2k badge 2x thumb
Thanks, Rob, for the direction.  I finally got this to work using a different model that only had a UI field in it.
(Edited)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Sweet!  Thanks for letting us know.