Skip to main content

I’m attempting to render a number field as a picklist.

Here’s what I’ve got so far:

var field = argumentsu0], value = argumentsu1], $ = skuid.$;  

field.metadata.picklistEntries = r
       { value: 30, label: ‘30 minutes’, defaultValue: false, active: true },
       { value: 60, label: ‘60 minutes’, defaultValue: true, active: true }
];
field.metadata.defaultValue = 60;
    skuid.ui.fieldRenderers.PICKLISTfield.mode;
}

It’s working, sort of.

With the defaultValue line I was trying to eliminate the “none” option, but I’m still getting “–None–” by default.
Is there a way to eliminate the --None-- option?

The values are returned as strings. Not sure if there’s a way to change that so that it outputs numbers. If there’s not, I can handle it on the other side with Number().

Thanks!

Is the field required? You can only eliminate the “–None–” option if the field is NOT required, otherwise it would be impossible for a user to leave the field blank. If the field IS required, then you can eliminate the --None-- option by using the following option:

field.options.addNoneOption = false;

Whenever you’re setting picklist field entries, value needs to be a string, not a number, same thing for for field.metadata.defaultValue.

FYI, the purpose of the defaultValue property on field metadata is to specify a value to insert into this field when creating a new record of the given object– the field.metadata.defaultValue property is not used after a record is first saved. 


Zach,

Thanks for the thorough explanation!
My renderer is working, even though I’m giving it numbers instead of strings. The field isn’t required, but it makes sense to make it required (at least in the ui, if not salesforce).


One quick additional question:

What does the ‘defaultValue’ in the definition of a picklist entry do (in bold below)?

field.metadata.picklistEntries = s
       { value: 30, label: ‘30 minutes’, defaultValue: false, active: true },
       { value: 60, label: ‘60 minutes’, defaultValue: true, active: true }
];


Currently, nothing.


ha. ok.


OK. So what does “active:true” do?  What happens with “active:false”? 

Doesn’t seem to change anything for me.