yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Why `validate` event at yii.activeForm.js submit form with forceValidate = true? #16493

Open mubat opened 6 years ago

mubat commented 6 years ago

I think, if user trigger validate event on Yii form, it shouldn't be submitted? If user want to submit form it trigger submit event.

it happens if call validate method with forceValidate = true:

$('#form-id').yiiactiveForm('validate', true);

If I was write, it need to disable submitting state after validate. Need add next command at https://github.com/yiisoft/yii2/blob/master/framework/assets/yii.activeForm.js#L404:

               ...
                } else {
                    updateInputs($form, messages, submitting);
                }
            });
            if (forceValidate) {
                $(this).data('yiiActiveForm').submitting = false;
            }
        },
        ...

Additional info

Q A
Yii version 2.0.15.1
PHP version 7.1.18-1+ubuntu16.04.1+deb.sury.org+1
Operating system Linux Mint 18.3
lubosdz commented 6 years ago

What exactly is the problem? Validation and submitting must be two separate actions.

mubat commented 6 years ago

@lubosdz exactly. But if set forceValidate = true it actual will be submitting. I think, will be good if:

I don't want to submit form when I call validate action.

lubosdz commented 6 years ago

Well, forceValidate argument was introduced 2 years ago to solve another issue - see: https://github.com/yiisoft/yii2/blame/02b469e8b6c037a4e028aaeaa52fdb3d9c059f24/framework/assets/yii.activeForm.js#L302