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.3k stars 368 forks source link

Series of selects #89

Open IL55 opened 10 years ago

IL55 commented 10 years ago

Hi,

Let's imagine that you want to get user location: country and city, i.e. form.onSubmit should produce: { "country": "USA", "city": "New Orleans" } How I can do it via series of dependent selects ?

I prepare example, to show what I ask: http://jsfiddle.net/9ffYY/8/

If you press on submit button, you can see "cityUSA" { "country": "USA", "cityUSA": "New Orleans" }

In that case post processing needed, i.e. some function should be change "cityUSA" to "city" and only after the post-processing, form can send data to server.

I put my question to stackoverflow due to largest community, and if you want to get some reputation points http://stackoverflow.com/questions/20404373/alpaca-form-generator-series-of-selects

Thanks, Igor

IL55 commented 10 years ago

Hi, I implemented what I described in previous letter. Could anyone review my solution ? From user point of view, I added "dataAlias" parameter, which means alias for data for serialization to/from JSON object,

        "cityUSA": {
            "dataAlias": "city",
            "dependencies": {
                "country": "USA"
            }
        }

More details here http://jsfiddle.net/9ffYY/15/

Here is pull request: https://github.com/gitana/alpaca/pull/92