JsFormValidatorBundle icon indicating copy to clipboard operation
JsFormValidatorBundle copied to clipboard

Recursive validation has no return value

Open KaiDream opened this issue 9 years ago • 1 comments

We have ran into an issue with validation triggering and comparing if the form is valid.

FpJsCustomizeMethods.validate({'recursive': true}) (ie: form.jsFormValidator('validate', {'recursive': true}) will always return false since .FpJsFormElement.validateRecursively() (https://github.com/formapro/JsFormValidatorBundle/blob/master/Resources/public/js/fp_js_validator.js#L47) has no return value when executed on: https://github.com/formapro/JsFormValidatorBundle/blob/master/Resources/public/js/fp_js_validator.js#L244.

I am not sure if this intended behavior or FpJsFormElement.validateRecursively() needs to be patched to return the proper form state.

KaiDream avatar Apr 27 '15 20:04 KaiDream

I noticed the same

Original code

FpJsFormValidator.js:46

this.validateRecursively = function () {
    this.validate();

    for (var childName in this.children) {
        this.children[childName].validateRecursively();
    }
};

With this snippet you can fix the recursive validation:

FpJsFormValidator.js:46

this.validateRecursively = function () {

    if (!this.validate()) {
        return false;
    }

    for (var childName in this.children) {
         if (!this.children[childName].validateRecursively()) {
             return false;
         }
    }

    return true;
};

boubbin avatar Nov 15 '19 13:11 boubbin