Render a text field as picklist field with specific values using custom field renderer

Jack Sanford
Jack Sanford San Antonio, TX 💎💎
edited January 12, 2018 in Questions
I've got a table where the object has a Value field, and sometimes I want that Value show as is, but sometimes I'd like it to render as a Yes/No dropdown that has a value of 1 or 0. That sometimes is dependent on a picklist field Benchmark Type on my object's master object. 

I've put together a snippet based on some research on the community, but I'm getting a console error that my picklistEntries variable is null and so no values can be pushed to it, specifically: 
"Cannot read property 'push' of null"

Here's my snippet:
var field = arguments[0],       row = field.row,      isPercentage = (row.Indicator__r.Benchmark_Type__c == 'Percentage') ? true : false;      value = skuid.utils.decodeHTML(arguments[1]),      metadata = field.metadata,      element = field.item.element,      $ = skuid.$;        if (isPercentage){        skuid.ui.fieldRenderers.PICKLIST[field.mode](field,value);    if (field.mode == 'edit'){    var picklistEntries = field.metadata.picklistEntries;    // picklistEntries.length = 0;  // I tried setting the length to see if it would help but it didn't        picklistEntries.push(         { value: '1', label: 'Yes', defaultValue: false, active: true  },         { value: '0', label: 'No', defaultValue: true, active: true }       );        }   }  else{  skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);  }



Comments

  • Mordechai
    Mordechai ✭✭✭
    edited January 12, 2018
    you may have to do something like this:
    var picklistEntries = [];  picklistEntries.push(...);  field.metadata.picklistEntries = picklistEntries;
  • Jack Sanford
    Jack Sanford San Antonio, TX 💎💎
    edited May 25, 2016
    THAT WORKED!! Thanks so much
  • Jack Sanford
    Jack Sanford San Antonio, TX 💎💎
    edited January 12, 2018
    With Mordechai's help here's the final snippet, even though I set my No value as Default = true, Yes showed up as the default until I switched the order in which they appeared. Also moved the skuid.ui.fieldRenderers.PICKLIST below the picklistEntries, it worked the other way sometimes but became stable moving it below
    var field = arguments[0],       row = field.row,            // set the render condition      isPercentage = (row.Indicator__r.Benchmark_Type__c == 'Percentage') ? true : false;      value = skuid.utils.decodeHTML(arguments[1]),      metadata = field.metadata,      element = field.item.element,      $ = skuid.$;    if (isPercentage && field.mode =='edit'){    //create a blank variable for picklist entries  var picklistEntries = [];    // set the picklist entries. note defaultValue doesn't matter, the first one will be default      picklistEntries.push(     { value: '0', label: 'No', defaultValue: true, active: true },   { value: '1', label: 'Yes', defaultValue: false, active: true  }       );      field.metadata.picklistEntries = picklistEntries;    // render the field as a picklist      skuid.ui.fieldRenderers.PICKLIST[field.mode](field,value);  }     else{            //use the default renderer  skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);  }
  • @"Jack Sanford" & @Mordechai ,
    I am new to Skuid.
    Can you kindly let me know if we can remove the -none- option which is coming by default and make the value in picklist entries with default value : true appear when the field is displayed.
  • Jack Sanford
    Jack Sanford San Antonio, TX 💎💎

    @RajeshBangalore you can remove the -none- option by making the field required. But if you want to change the label on it, I don't know, have a separate question here asking that https://community.skuid.com/discussion/8015609/change-none-label-on-picklist-created-by-custom-field-renderer/p1?new=1

    I'm not sure what purpose defaultValue has, I have ended up removing it from that snippet, doesn't seem to function

  • RajeshBangalore
    edited April 9, 2021

    Hey @Jack Sanford ,

    Thanks for the reply,

    I used a global action to update row before show popup to achieve default value. It solved my problem. But now requirement changed asking the picklist rendered should also support a new value to be typed in if needed along with picklist values that needs to be selected and the one which is defaulted. Can you kindly help me to see if this same can be done over a combobox. I mean can we render this as a combo box? If so how?

    I really appreciate the help in advance.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!