Rendering integer as picklist.

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I'm attempting to render a number field as a picklist.

Here's what I've got so far:

var field = arguments[0], value = arguments[1], $ = skuid.$;  

field.metadata.picklistEntries = [
       { 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.PICKLIST[field.mode](field,value);
}

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!
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
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. 
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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).
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
One quick additional question:

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

field.metadata.picklistEntries = [
       { value: 30, label: '30 minutes', defaultValue: false, active: true },
       { value: 60, label: '60 minutes', defaultValue: true, active: true }
];
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Currently, nothing.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
ha. ok.
Photo of Tony Sirna

Tony Sirna

  • 976 Points 500 badge 2x thumb
OK. So what does "active:true" do?  What happens with "active:false"? 

Doesn't seem to change anything for me.