Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fieldSubmit not calling validate method #509

Merged

Conversation

qduc
Copy link
Contributor

@qduc qduc commented Oct 8, 2018

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Bug fix
  • What is the new behavior (if this is a feature change)?
    Beside the bug fix, schema.onValidationError should be optional.
    Previous behaviour, when validation failed, onSubmit still get called if onValidationError is not exists.
  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No
  • Other information:

@coveralls
Copy link

Coverage Status

Coverage remained the same at 89.916% when pulling c82c44b on qduc:fix-fieldsubmit-validation into 0593b87 on vue-generators:master.

@lionel-bijaoui
Copy link
Member

@qduc Thanks a lot for this very good PR !

@lionel-bijaoui lionel-bijaoui merged commit de6b323 into vue-generators:master Oct 10, 2018
let handleErrors = errors => {
if (!isEmpty(errors) && isFunction(this.schema.onValidationError)) {
this.schema.onValidationError(this.model, this.schema, errors, $event);
if ((validateAsync && !isEmpty(errors)) || (!validateAsync && !errors)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the addition of this extra conditional? Haven’t had my coffee yet, but it seems to be redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because at this point, we still don't know if this form is valid or not.

If you mean there is already a check here
if (errors && isFunction(errors.then))

Because of the isFunction(errors.then) condition, a non-async valid result still go to the else clause and calls handleErrors function

@zoul0813
Copy link
Member

That logic was intentional, iirc, to make it backwards compatible with how non-async validation worked in the past.

Valid or not, the submit callback was always called previously. The newer async code changed this, and to be backwards compat ... you have to enable async to get onValidationError enabled as well.

This may introduce breaking changes to code that hasn’t updated to enable async validation (v3 should force async validation, so all validate calls return a promise).

@qduc
Copy link
Contributor Author

qduc commented Oct 11, 2018

The reason I changed this logic is because I think it is unexpected to enable validateBeforeSubmit but the form will call onSubmit anyway, whether it is valid or not.

So we let the user decide if they still want to submit or not but we don't provide a way for them to retrieve the validation result or an error array. As far as I can see, onSubmit's arguments doesn't have that data.

I'm sorry that I make this change without discussion first, if you think this is intentional and should be kept that way I'll make another PR to revert this.

@zoul0813
Copy link
Member

@qduc your logic is correct, and I agree with it ... but I'm just not sure if it should be added to the v2 branch.

@lionel-bijaoui do you have any thoughts on this? My concern is backwards compatibility... perhaps we can curtail any issues there with a more elaborate update in the CHANGELOG, and a note in the README?

@lionel-bijaoui
Copy link
Member

If this is really breaking thing, I will revert this commit.
I'm sorry for merging so fast, it looked good to me.

@zoul0813
Copy link
Member

I don’t think it’s “breaking”, but we need to clearly state the change in the release logs

@lionel-bijaoui
Copy link
Member

Ok, sorry again

@lionel-bijaoui lionel-bijaoui mentioned this pull request Oct 18, 2018
3 tasks
lionel-bijaoui pushed a commit to lionel-bijaoui/vue-form-generator that referenced this pull request Oct 18, 2018
zoul0813 added a commit to zoul0813/vue-form-generator that referenced this pull request Dec 22, 2018
…o v3

* 'v3' of github.com:vue-generators/vue-form-generator:
  Bump version to 3.0.0-beta.7 - Update dependencies - Export dist files
  Single export - No more core vs full since both are the same right now - Optionnal fields will be removed from it in future update
  Clean useless folders
  Update submodule dev
  Custom legend block for group - Possibility to use scoped-slot to customise fully how legend is build - Expose `group` and `groupLegend` in slot prop
  vue-generators#509
  vue-generators#522
  vue-generators#521
  vue-generators#501
  Fix deep property path not working
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants