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

Field is excluded in the Alpaca.getValue() when dependent on hidden field #771

Open shoaibshrafi opened 2 years ago

shoaibshrafi commented 2 years ago

Following is the code in alpaca.js version 1.5.27 Line number 24336 to 24344 Any one know the reason to not include the field that is dependent on hidden field although hidden field value included in the value

I think following check should be removed.

//
// NESTED HIDDENS DEPENDENCY HIDES (ALPACA EXTENSION)
//

// final check: only set valid if the dependentOnPropertyId is showing
if (dependentOnField && dependentOnField.isHidden())
{
       valid = false;
 }

return valid;

as per following example field2value is not included in the alpaca.getValue() and getting value as {'field1': 'Value1'} instead of {'field1': 'Value1', 'field2': '100'}

var alpaca = $('#form').alpaca();
var value = alpaca.getValue();

Here is the json schema:

{
    "$schema":"https://json-schema.org/draft/2020-12/schema",
    "$id":"https://gso.org.sa/aajel/api/json/schema?version=1",
    "description":"Here is custom  form generated by json schema using alpaca",
    "type":"object",
    "dependencies": {
        "field2": ["field1"]
    },
    "properties":{
        "field1": {
            "type":"string",
            "enum":[
                "Value1",
                "Value2"
            ]
        },
        "field2":{
            "type":"string",
            "enum":[
                "100",
                "200",
                "300",
                "400"
            ]
        }
    }
}   

Here is the options:

{
   "fields":{
      "field1":{"type": "hidden", "default": "Value1"},
      "field2":{
        "dependencies": {
              "field1": 'Value1'
               }
       }
}