Comments (7)
Use rules="required"
on each field and then both fields are required.
from vee-validate.
Hello @hanzelkatomas,
Thanks for taking time to reply to my issue.
Are you sure it works the same for checkboxes with the same name
?
I did a reproduction and it behaves like what I described. Even when all checkboxes with the same name are required
and 1 checkbox only is checked, the test succeeds.
https://stackblitz.com/edit/vee-validate-v4-checkboxes-r4z6y5?file=src%2FApp.vue
from vee-validate.
Follow this example:
https://stackblitz.com/edit/vee-validate-v4-checkboxes-wvbtku?file=src%2FApp.vue
You have to use different names for different inputs. Also each input should have it's own error message component.
Also, you should rather use validation schema (yup, zod, valibot), than this field level rules. It's the modern way of how forms validation is done today. You can pass validation-schema
object to <Form>
component.
More on this here: https://vee-validate.logaretm.com/v4/guide/components/validation/#validation-schemas-with-yup
from vee-validate.
@hanzelkatomas In my usecase I have to use the same name (which is possible with HTML5 and VeeValidate), that's why I specifically asked for help with the same name.
I'm asking to mimic what is possible with native HTML, same name and fields that can be required individually.
Example with HTML5 validation: https://stackblitz.com/edit/stackblitz-starters-mdjh8u?description=HTML/CSS/JS%20Starter&file=index.html&terminalHeight=10&title=Static%20Starter
In my case I cannot use validation-schema
in my use case as each field is responsible for its own validation and I cannot put it on the <Form>
component level which is unaware of the children in the CMS.
from vee-validate.
If you are going to use same name for multiple inputs, then vee-validate is going to treat them as one input (if all checkboxes have the same "value" attribute). Then if you check one checkbox, the other checkboxes with the same name are gonna be checked. It's expected that different inputs have different name and you should implement your form with that in your mind.
If you really need have the same name property (which you shouldn't), then you can try this validation:
https://stackblitz.com/edit/vee-validate-v4-checkboxes-wvbtku?file=src%2FApp.vue
from vee-validate.
Thanks for helping!
The length:3
that you recommend is interesting if I manage to have a Checkbox group component that would be aware of how many checkboxes it have and all of them are mandatory.
I think you are talking none sense for checkbox names though, it is completely possible to have the same name for different checkbox. It is possible with native HTML and VeeValidate, so there no reason I "shouldn't use this".
The only difference is the model will be an array or a single value exactly like Vue v-model for checkboxes.
So this is not my point and I'll stop the debate about this topic.
from vee-validate.
It seems my usecase evolved so the length:3
is not enough as it should be able to handle both mandatory and optional options so I'm still not sure how to achieve that.
from vee-validate.
Related Issues (20)
- Custom component does not trigger change event on form HOT 1
- Ability to customize interpolation prefix/suffix HOT 1
- Force resetting a form should also force reset initial values instead of merging
- Components. Yup. It is not possible to set the default value via `.default()`. I can't delete fields using `.strip()` HOT 2
- Unable to display a label when using vscode-dropdown with vee-validate Field
- I am using vee-validation but my initial values not geeting update HOT 1
- There is no way to tell vee-validate our class instance is whole and no need for PartialDeepObject HOT 3
- useField object structure HOT 1
- vee-validate V4 - how to create a custom error message in a function and get it displayed?
- <title>Vee-validate V4 - lazy validation not working - rule is being called on each keystroke HOT 5
- `meta.required` not detected when validation schema is passed after `useForm()` is called HOT 1
- d HOT 1
- useFieldParam
- [docs]: Codepen on the Validation page does not work
- 4.12.7 broke zod validation HOT 2
- Not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>' error on toTypedSchema HOT 1
- Dynamic custom checkbox and dynamic input value update issue - Composition API
- Trying to set a custom error message using setFieldError against a Field
- Custom input not working with yup.ref()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vee-validate.