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

Array conditional dependencies not working in 1.5.24 #632

Closed Nj0376 closed 6 years ago

Nj0376 commented 6 years ago

Hi,

In versions prior to 1.5.24 the following dependency code works. If I select "Other" as the option then the dependent textbox appears in older version but does not in the current version. If I change the type from array to string it works in 1.5.24, however for my backend system I need to have the array type working like it was previously. Is this a known issue or is there an alternative way to have a dependency on an array type?

    $("#field1").alpaca({
        "schema": {
            "type": "object",
            "properties": {
                "choice": {
                    "title": "Pick an option",
                    "type": "array",
                    "enum": ["OptionA","OptionB","Other"]
                },
                "other_option": {
                    "title": "Enter other option",
                    "type": "string",
                },
            },
            "dependencies": {
                "other_option": ["choice"]
            }
        },
        "options": {
            "fields": {
                "choice": {
                    "type": "checkbox"
                },
                "other_option": {
                    "dependencies": {
                        "choice": "Other"
                    }
                }
            }
        }
    });
futon88 commented 6 years ago

I was having a similar issue. Moving the enum to an 'items' element (with type string) solved it for me. Essentially, example 7 on http://www.alpacajs.org/docs/fields/checkbox.html.

Try changing this:

"choice": {
    "title": "Pick an option",
    "type": "array",
    "enum": ["OptionA","OptionB","Other"]
},

to this:

"choice": {
    "title": "Pick an option",
    "type": "array",
    "items": {        
        "type": "string",
        "enum": ["OptionA","OptionB","Other"]
    }
},
Nj0376 commented 6 years ago

That’s great. Should’ve thought of that. Thank you.