Skip to content

validateBeforeSubmit doesn't prevent the submit #434

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

Closed
afourmeaux opened this issue Apr 6, 2018 · 2 comments
Closed

validateBeforeSubmit doesn't prevent the submit #434

afourmeaux opened this issue Apr 6, 2018 · 2 comments

Comments

@afourmeaux
Copy link

afourmeaux commented Apr 6, 2018

Current :

When an input submit has validateBeforeSubmit setted to true the form is not prevented from submitting and call the onSubmit callback when there is errors.

Expected :

It should not submit if there is errors.

@afourmeaux
Copy link
Author

afourmeaux commented Apr 6, 2018

I found a solution to prevent the submit when there is an error, but i think validateBeforeSubmit should already do that.
So, on your <vue-form-generator> listen to the validation event with a method that will set a data with the isValid you got from the validation event. Then on your form listen to the submit event and call a method that will check the data setted and will trigger the event.prevenDefault if there is an error.

Code example :

<template>
  <form @submit="onSubmit">
    <vue-form-generator ... @validated="setValidState"/>
  </form>
</template>

<script>
  import VueFormGenerator from 'vue-form-generator';

  export default {
    ...
    data() {
      return {
        isValid: false,
      };
    },
    methods: {
      setValidState(isValid) {
        this.isValid = isValid;
      },
      onSubmit(event) {
        if (!this.isValid) {
          event.preventDefault();
        }
      },
    },
    ...
  };
</script>

zoul0813 added a commit to zoul0813/vue-form-generator that referenced this issue Apr 22, 2018
…idationError and call preventDefault when onValidateBeforeSubmit is true

We can't prevent the submit after waiting for async validation, so we just prevent it before calling any validation and let the user
manually submit the form in the `onSubmit` handler, if it validates.
@zoul0813
Copy link
Member

Please refer to #408 - I recommend not placing VFG inside of a form, if you do, that form should have it's own onSubmit handler.

I've pushed a change that calls $event.preventDefault() when using validateBeforeSubmit: true, which means that onSubmit and onValidationErrors will both require you to manually submit the form if you would, as we can't capture async validation and prevent the submit event on failure.

zoul0813 added a commit to zoul0813/vue-form-generator that referenced this issue Apr 22, 2018
* feature/434-validateBeforeSubmit:
  closes vue-generators#434, vue-generators#408 - added $event to onValidationError and call preventDefault when onValidateBeforeSubmit is true
  fieldUpload.vue: rename event to
  Fix vue-generators#422 fieldUpload  event throws ReferenceError in Firefox
  Fix NaN with value 0 on input type number/range.
  closes vue-generators#419, vue-generators#420 - links to new public custom fields
  Add issue and PR template
  2.2.1 releases
  setup automate releasing
  ...
  vue-generators#409 - fixed id property in fieldUpdate

# Conflicts:
#	dist/vfg-core.css
#	dist/vfg-core.js
#	dist/vfg.css
#	dist/vfg.js
#	package-lock.json
#	package.json
#	src/fields/core/fieldUpload.vue
zoul0813 added a commit that referenced this issue Apr 24, 2018
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

No branches or pull requests

2 participants