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

"false" should be a valid value for a "required" boolean checkbox #748

Open ndbroadbent opened 4 years ago

ndbroadbent commented 4 years ago

I saw the docs for the Checkbox Field, and I think the code is not properly handling "required" fields:

required | boolean | Indicates whether the field's value is required. If set to true, the field must take on a valid value and cannot be left empty or unassigned.

When a checkbox is unchecked, this should set the field value to "false", and this should be considered a valid value. Right now I am unable to submit the form and the checkbox shows a validation error when it is unchecked.

(Might also be related to #528, but that issue didn't have enough context.)

ndbroadbent commented 4 years ago

Ahhhh, this is the isEmpty function in ListField:

        isEmpty: function()
        {
            return this.data.length === 0;
        },

And Alpaca.Fields.CheckBoxField inherits from Alpaca.Fields.ListField.

Otherwise it would have worked fine if it used the isEmpty function from Field:

        isEmpty: function()
        {
            return Alpaca.isValEmpty(this.getValue());
        },