gitana / alpaca

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking, dynamic user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.
http://www.alpacajs.org
Other
1.29k stars 371 forks source link

How to programatically add options on a select? #586

Open punto- opened 6 years ago

punto- commented 6 years ago

Hi.

How do I programatically add options to a select? I tried using the "add()" function as if it was a "normal" html select widget but it doesn't seem to work. Is there API to do this, or do I have to somehow obtain the underlying html element? (I tried with getControlEl() and it didn't work either).

Thanks

WhileTrueEndWhile commented 6 years ago

See http://www.alpacajs.org/docs/api/observables.html. Example:

{
    "schema": ...,
    "options": ...,
    "postRender": function(control) {
        control.schema.enum = [ ... ];
        control.refresh();
    }
}
muelli commented 6 years ago

maybe simple dependencies are what you want: http://www.alpacajs.org/docs/api/dependencies.html