简体   繁体   中英

vuejs-datepicker with required attribute gets submitted without value

vuejs-datepicker setting html required attribute on input fields doesn't work as expected and submits the form without have a input value.

<form>
  <datepicker placeholder="Select Date" required></datepicker> 
  <button>Submit</button>
</form>

You can use the above code and test here: https://codesandbox.io/s/p92k8l717

Here is the link to repo and doc: https://github.com/charliekassel/vuejs-datepicker

You can use vee-validate library to validate this like:

<date-picker :input-class="{'input': true, 'is-danger': errors.has('date') }"
            v-model="date"
            :disabled="state.disabled"
            placeholder="Select date"
            input-class="form-control"
            ></date-picker>
    <span v-show="errors.has('date')" class="help is-danger-red">{{ errors.first('date') }}</span>
    <input type="hidden" name="date" v-validate="'required'" v-model="date">

You can use this trick to solve this issue, It's works for me.

您可以使用input-attr设置所需的属性,如:input-attr="{required: 'true'}"

I was facing the similar issue, not with this plugin but some other plugin and one get around that worked for me was using vee-validate

This is the best validation plugin available for vue-js.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM