Change none label on picklist created by custom field renderer?

Jack Sanford
Jack Sanford San Antonio, TX 💎💎

Is there a way to get at the none label in a picklist created by a custom field renderer? I have an integer field that is conditionally rendered as a Yes/No picklist. We've been using a separate field Not_Applicable__c but I'd rather just use the blank value of my Value__c field and relabel to say "n/a"

I've tried field.options.nonelabel="n/a" and field.options.addnoneoption="true" which mimics what shows up for a normal field in the XML when you make it required and add a none option, but they don't have an effect. They either don't add a none option to my radio buttons, or if I make the field not required, the default null option shows "-none-"

Here's the snippet I am using

var field = arguments[0], 
				    row = field.row,
				    value = skuid.utils.decodeHTML(arguments[1]),
				    metadata = field.metadata,
				    element = field.item.element,
				    $ = skuid.$;
				    isNA = (row.Not_Applicable__c);
				    isYes = (row.Type__c == 'Yes') ? true : false;
				    isNo = (row.Type__c == 'No') ? true : false;
				    response = row.Value__c;
				    console.log(response);
				
				
				if (!isNA){
				    field.item.element.removeClass("gray-row");
				    field.item.element.removeClass("nodisplay");
				
				
				if (isYes){
				
                //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: 'Yes', defaultValue: false, active: true },
				 { value: '1', label: 'No', defaultValue: false, active: true  }


				);
				    field.metadata.picklistEntries = picklistEntries;
				    field.options.type = 'RADIO_BUTTONS';
				   
				
				// render the field as a picklist
				    skuid.ui.fieldRenderers.PICKLIST.edit(field,value);
				
				} 
				if (isNo){


				    //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: false, active: true },
				 { value: '1', label: 'Yes', defaultValue: false, active: true  }
				   
				);
				    field.metadata.picklistEntries = picklistEntries;
				    field.options.type = 'RADIO_BUTTONS';
				
				// render the field as a picklist
				    skuid.ui.fieldRenderers.PICKLIST.edit(field,value);
				field.item.element.removeClass("gray-row");  
				}
				
				if (!isNo && !isYes){


				    //use the default renderer
				skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
				}
				}
				
				if (isNA){
				    
				field.item.element.addClass("gray-row");
				field.item.element.addClass("nodisplay");


				
				} 

Answers

  • Germany3
    Germany3 🛠️ 

    Hey @Jack Sanford , I have a few questions:

    1. are you trying to create or change/modify that label
    2. are you trying to render the picklist as "none" when it requires a default value?

    Also, have you seen this post?


  • Jack Sanford
    Jack Sanford San Antonio, TX 💎💎

    Hi @Germany3, I'm trying to achieve what you can do in the builder ui for a required picklist field - where you can add a none selected option, and change the text that shows up when none selected. I'm just trying to do that in this snippet since the actual field is an integer and I'm only sometimes making it a picklist

  • Germany3
    Germany3 🛠️ 

    Hey @Jack Sanford , i found another thread that could help with your use case:


    If you see Zach's solution, it provides a good example that is (or close to) what you're trying to achieve.

    skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
    var select = field.element.find('select');
    if (select.length) {
        // Remove unwanted entries
        $.each(select.children('option'),function(){
             if ($(this).val()==='blah')) $(this).remove();
        });
        // Add new entries
        select.append($('<option value="cheese">Cheese</option>'));
     }
    

    you can add or remove or add the value of what you are trying to change.


    I hope this helps!

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!