Closed JasonHenson closed 6 years ago
Looking at Bootstrap 4, this is a normal field after validation
<div class="col-md-6 mb-3">
<label for="validationServer03">City</label>
<input type="text" class="form-control is-invalid" placeholder="City" required>
<div class="invalid-feedback">
Please provide a valid city.
</div>
</div>
We can have the invalid-feedback
and the label, but we cannot add the is-invalid
class to your inputs, as those will be provided via slots. Do you think this would be sufficient?
That should be fine. Thanks for the quick response!
<form-wrapper :validator="$v.form">
<form-group name="email">
<template slot-scope="{ validator, hasErrors }">
<input
class="form-control"
:class="{ 'is-invalid': hasErrors, 'is-valid': !hasErrors }"
type="email"
name="email"
@input="validator.$touch()">
</template>
</form-group>
<form-group name="name">
<template slot-scope="{ validator, hasErrors }">
<input
class="form-control"
:class="{ 'is-invalid': hasErrors, 'is-valid': !hasErrors }"
type="text"
name="name"
@input="validator.$touch()">
</template>
</form-group>
</form-wrapper>
This is an example how you can add is-valid
and is-invalid
classes to your inputs. Its a bit more boilerplate than I would like to, but its either this, or rendering an input for you (which i will not do).
If you like this, I will push the template tomorrow as its late now.
Alright. Managed to remove some boilerplate. I think this looks allot better.
<form-group name="first_name">
<template slot-scope="{ attributes, events }">
<input
v-bind="attributes"
v-on="events"
type="text"
v-model="nestedObject.first_name">
</template>
</form-group>
The last example looks much cleaner for sure. I wouldn't want to have the input rendered anyways as I use bootstrap-vue component. I really appreciate you working on this so fast.
Template is done. Updated the rest of the templates to have bindingProps and bindingActions.
Also added some new features as well. Will release later today v2.1
@JasonHenson try now :)
thank you it is adding support so fast -- it is adding the correct classes now!
Unrelated question, do you have any plans to support Bootstrap-vue? I have to use a non-component form-group, etc. to get validation to function correctly.
Hey @JasonHenson I looked at bootstrap-vue and you can totally use their formgroup. Just wrap it with your component that renders the form-group and passes the invalid-state to it. Something like this:
<template>
<b-form-group
:invalid-feedback="firstErrorMessage"
:state="isValid"
>
<slot
:state="isValid"
/>
</b-form-group>
</template>
<script>
import { singleErrorExtractorMixin } from 'vuelidate-error-extractor'
export default {
name: 'FormElement',
extends: singleErrorExtractorMixin
}
</script>
Then you can use it like so:
<form-element :validator="$v.form.input">
<template slot-scope="{ state }">
<b-form-input id="input1" :state="state" v-model.trim="name"/>
</template>
</form-element>
I wrote this without testing at all, but I think it should work :)
@dobromir-hristov is the component auto register or still need to register ? thanks
and i cant get it work with the code above.. thanks
If you pass it to template property it will get registered, but you can do it manually it doesn't matter
thanks very fast response <3 . one more thing base on the code above .. state is false but the input is red.. i dont know why..
if state is false, it will be red. That would mean the isValid property in the error extractor is returning false.
ow my bad.. sorry .. thanks :) hope to see more supported framework like bootstrap-vue :)
Well I have tried with Quasar and Bulma and it works perfectly. Maybe I should make a page on how to use them...
@dobromir-hristov please do :) that would be very helpful
please when you do the page please make initial state to null :) if possible thanks
Is it always green atm ?
always red ..
<template>
<b-form-group
:invalid-feedback="firstErrorMessage"
:state="formGroupState"
>
<slot
:state="formGroupState"
/>
</b-form-group>
</template>
<script>
import { singleErrorExtractorMixin } from 'vuelidate-error-extractor'
export default {
name: 'FormElement',
extends: singleErrorExtractorMixin,
computed: {
formGroupState () {
return this.preferredValidator.$dirty ? this.isValid : null
}
}
}
</script>
that is working.. thank you :)
Will update it with next release.
Hey, sorry for the delay -- I was able to get your example working. Thank you!
please include vuetify too when you have time thanks :)
Wow.. thank you. I got it working with vuetify from your previous example, but i think this is better :) thank you
Example is added to the docs now. https://dobromir-hristov.github.io/vuelidate-error-extractor/other_frameworks.html#usage-with-bootstrapvue
Any plans to support Bootstrap 4 in the very near future?