Custom picklist renderer when option source is a model
I would like to render a custom picklist for a reference field, populating the picklist with rows from a model. There are two reasons that the standard picklist renderer with a model source doesn't seem to meet my needs in this case:
- When the field is in a non-editable state I don't want it to render a link - just text.
- The field is in a table, and ideally I would like to prevent the same item being selected twice in different rows by hiding items that are already in use.
3
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
var customSelect = skuid.ui.renderers.PICKLIST.edit({
If you change... ...to... ...does that work?
Also, you can drop that "console.log(skuid.$(this));" bit. That's just a slightly embarrassing slip on my part to leave debugging code in the "official response" to community question.
Since you can use a custom field renderer on any field, you don't have to create a dummy field for your "LDS_Rules" Picklist, even if you are using core Skuid components for your layout like Table and Field Editor. Drop an ID field into your Table or Field Editor and set the Field Renderer to a snippet which builds out your Picklist. You'll have to handle your own submits (e.g., go get the selected value and send it off to Apex for processing), but our newly release Actions Framework makes this a little easier than it used to be. You can save the record in the table/field editor like you always did before with Skuid, but then run a snippet which does the callout if the initial save was successful, for instance.
I think the issue is with the "value : customOpts" part. Our PICKLIST renderer's edit mode looks for two properties that have to deal with the selected value: value and defaultValue. Both are simple values (e.g. if you want "5" selected, set value or defaultValue to "5"). As you probably guessed, value takes priority over defaultValue.
In your snippet, you're sending in the whole customOpts Array for value, so the renderer can't find a match on value, and the resulting select box has the first value selected by browser default. Try this instead: Does that seem to behave as you expect?
I'd like to include a defaultValue, but it doesn't seem to be working the way I'd expect. Here's my code: The goal here is to create a dropdown list of the initials of certain users. I have the Initials__c field on the Users object (the Nurses model). I want the value to default to the running user. I'm getting the correct true/false for defaultValue within initials, but it's not coming through to the picklist.
Do I need to set the defaultValue in customSelect instead?
Yep, you got it. You need to send the actual value of the option that you want selected into customSelect. defaultValue gets sent into the field renderer (skuid.ui.renderers.PICKLIST.edit), not set as a boolean on an individual option in the entries array (var initials in your code). Put another way (for anyone TL;DRing for code snippets)... Make sense?
1) Remove duplicate values from the picklist (aggregate model is not a solution since the field in question is a datetime field and I need more granularity that HOUR_IN_DAY)
2) Define rules to hide / display values based on whether there are 2 instances / 3 instances of the duplicate (again, aggregate model and HAVING xml hack won't apply here unfortunately)