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

Alpaca conditional select lists #562

Open philbaney opened 6 years ago

philbaney commented 6 years ago

I'm relatively new to Alpaca Forms, I have a form with several select lists loaded from data sources in a controller/view framework, this is working fine. How can I dynamically build a select's url e.g "dataSource":"url?id=Z" where Z is say an id from a previous 'select'?

WhileTrueEndWhile commented 6 years ago

Normally, you would display two forms here. First the form with the selection field and then the one with the dependent data source. Very roughly according to this pattern:

const config1 = {
  "properties": {
    "myProperty": ...
  },
  ...
  "form": {
    "buttons": {
      "submit": {
        "click": function() {
          const dataSource = "url?id=" + encodeUriComponent(this.getValue().myProperty);
          const config2 = {
            ...
            "dataSource": dataSource
          };
          $(...).alpaca(config2);
        }
      }
    }
  }
};
$(...).alpaca(config1);

Another possibility, which should not be possible without own network queries and the following changes of the configuration at runtime, would be the options tree: http://www.alpacajs.org/docs/fields/optiontree.html

I hope I could help you further...