Disabled submit button, but valid form data will not enable it (vee-validate)

a coder

I'm attempting to disable my form's submit button until valid data is entered for each of the controls.

After entering correct data for each of the fields, the submit button remains disabled.

Markup:

<div id="app">
  <form action='#' method='POST'>

    <div class="columns">

      <div class="column">
        <div class="field">
          <div class="control">
            <label class="label">Last Name</label>
            <input v-validate="'required'" :class="{'input': true, 'is-danger': errors.has('lastname') }" class="input" name="lastname" type="text">
            <span v-show="errors.has('lastname')" class="help is-danger">{{ errors.first('lastname') }}</span>
          </div>
        </div>
      </div>

      <div class="column">
        <div class="field">
          <div class="control">
            <label class="label">Desk Number</label>
            <input v-validate="'required'" :class="{'input': true, 'is-danger': errors.has('desknum') }" class="input" name="desknum" type="text">
            <span v-show="errors.has('desknum')" class="help is-danger">{{ errors.first('desknum') }}</span>
          </div>
        </div>
      </div>
    </div>

    <button :disabled='!isComplete' class="button is-link" name='submit_data' value='go'>Submit</button>
  </form>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vee-validate/2.0.9/vee-validate.min.js">
<script>

            Vue.use(VeeValidate);
            new Vue({
              el: "#app",
              template: '#app',
              data() {
                return {
                  p_pat_name_first: null,
                  p_pat_name_last: null,
                  p_pat_date_birth: null,
                  p_pat_gender: null,
                  p_pat_twin: null,
                  p_emory_id: null,
                  p_mother_name_first: null,
                  p_mother_name_last: null,
                  p_parent_phone_primary: null,
                };
              },
              computed: {
                isComplete() {
                  return
                  this.p_pat_name_first &&
                    this.p_pat_name_last &&
                    this.p_pat_date_birth &&
                    this.p_pat_gender &&
                    this.p_pat_twin &&
                    this.p_mother_name_first &&
                    this.p_mother_name_last &&
                    this.p_parent_phone_primary;
                }
              }
            });

</script>

Fiddle

What am I doing wrong that is not allowing the Submit button to enable itself when the form is complete and valid?

Ryley

Well, simply put, your condition in isComplete() refers to values in your data that have no bearing on the form. None of the fields in your form have a v-model, so changing them has no effect on the variables referenced in inComplete().

The normal way in vee-validate to check if any fields are not valid is like this:

<button :disabled="errors.any()" type="submit">Submit</button>

That will only disable the Submit button after the form becomes invalid, so on page load it will look enabled until the user does something to the form that makes it invalid.

See a working example here (with one input having v-model set): https://jsfiddle.net/ryleyb/v7a2tzjp/8/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

jQuery Validate plugin, enable submit button when form is valid

Vee Validate 3 catch errors on form submit

Vee-validate Validate on blur prevents form submit

To disable/enable a button submit in a form

Disabled submit button if form is invalid angularjs

How to validate Form in React by pressing submit button

How to correctly validate and submit if form is valid with ant design form with typescript

Enable Submit Button After Form fields are fill

Enabling a disabled form button after submit & browser back button

How to validate and restrict submit when form not valid using jQuery

Validate Registration Form in Modal And Submit data in database

Enable submit button when all input fields are valid in Hyperscript?

Javascript - Enable Submit button when all input is valid

How to enable submit button When I entered data in all input tags in the form

Which is valid format for vee-validate 3?

blank the field on Submit (vee-validate vue)

Changing input type "Button" to "Submit Button" to validate php form

How to validate inputs inside form and submit button outside the form

How to validate a form when the submit button is outside of this form, with angularJs?

Yii2: Submit and validate a form by using a button outside the form

Angular 4 button disabled even if the form has valid values

Form submit button stays disabled after ajax post

html button stay in disabled status after a form submit

Angular, Disable submit button using [disabled] to check form validity

Enable All Command button if it's disabled in a user form excel VBA

cannot enable a disabled button

Using Vee-validate to disable button until form is filled out correctly

Issue with vee-validate in Vue 3 - Multiple Button Elements Triggering Form Submission

Validate child input components on submit with Vee-Validate