Dynamically add options to a picklist (Fieldin a Template )

  • 1
  • Question
  • Updated 3 years ago
  • (Edited)
Hi,
I have a picklist field in a template, and I want to add options dynamically to this picklist. how could I achieve this?

<select name="firstYearOfAdvice"  onblur = "onFirstYearOfAdvice();" id="firstYearOfAdvice" >
     <option value="">--None--</option>
</select>

note : I think I cannot use picklistEntries as I use a SKUID template and which contains pure HTML stuff?

Thanks and appreciate your help.
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
If I understand correctly,  you have a picklist field included in a template (on a field editor).  When the user clicks on the template they get a popup where each field in the template can be edited.  In this scenario, when the user clicks on the template to open the popup and edit the picklist field - you want to do some customization of the picklist values available. 

If this is the case - you should look at the template properties.  Its  "edit mode behavior" should be set to "Show custom popup"   In this popup you can have full control over the fields - using custom renderers that manipulate the options provided.  
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb
Sorry Rob, that's not what I meant,  

I have a pure html dropdown in the skuid template. which contains the above mentioned code snippet, and I want to access this field from a javaScript and add <option>s dynamically such as,

skuid.$('#firstYearOfAdvice').append($('<option>', {       
        value: '2000',
        text: '2000'
 })); 
/*
<will be adding a list of options....>
*/

Please correct me if the approach is wrong.
Thank you


Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,026 Points 20k badge 2x thumb
I think that approach makes sense.