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 370 forks source link

Infinite loop when clearing a form that has an array with minItems > 0 #570

Open ndbroadbent opened 6 years ago

ndbroadbent commented 6 years ago

Infinite loop is happening here: https://github.com/gitana/alpaca/blob/7e221a1fd8d7907ffd5d32e000b4612ff40ade39/src/js/fields/basic/ArrayField.js#L311-L328

I'll debug some more and maybe send a PR.

ndbroadbent commented 6 years ago

It's because the removeItem function refuses to do anything unless this._validateEqualMinItems() is true. In my case, that was always returning false, so it got stuck in an infinite loop.

My quick workaround is to add a force argument to ignore the validation:

        removeItem: function(childIndex, callback, force)
        {
            var self = this;

            if (this._validateEqualMinItems() || force)
            {

And I changed the calling code to:

self.removeItem(i, null, true);

Please let me know if you would like a PR for this, or if there's a better way to solve the problem.