forEach helper makes new entries to the collection dirty
See original GitHub issueUsing the sample code given in the docs for forEach:
<template>
<div
v-for="(input, index) in state.collection"
:key="index"
:class="{
error: v$.collection.$each.$response.$errors[index].name.length,
}"
>
<input v-model="input.name" type="text" />
<div
v-for="error in v$.collection.$each.$response.$errors[index].name"
:key="error"
>
{{ error.$message }}
</div>
</div>
</template>
<script>
// setup in a component
import { helpers, required } from '@vuelidate/validators'
import useVuelidate from '@vuelidate/core'
import { reactive } from 'vue'
export default {
setup () {
const rules = {
collection: {
$each: helpers.forEach({
name: {
required
}
})
}
}
const state = reactive({
collection: [
{ name: '' }, { name: 'bar' }
]
})
const v = useVuelidate(rules, state)
return { v, state }
}
}
</script>
If I call $touch on collection, and then a new element is added to the collection, it’ll be dirty as soon as it’s added. I would expect that the existing elements would be dirty, and the new ones wouldn’t. That way, errors wouldn’t be displayed immediately and would instead require the user to interact with the element, as it’s intended.
For example, this sample from an older version of vuelidate does just that: https://vuelidate.js.org/#sub-collections-validation
How do I get this behavior in the current version?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
foreach - Ghost Handlebars Theme Helpers
{{#foreach}} is a special loop helper designed for working with lists of posts. It can also iterate over lists of tags or users...
Read more >What does [].forEach.call() do in JavaScript? - Stack Overflow
[] is an array. This array isn't used at all. It's being put on the page, because using an array gives you access...
Read more >Avoid forEach - ÆFLASH
It is a un-semantic method. There are better iteration functions. There is map , which creates a new array with the results of...
Read more >Logic Apps foreach and variables - Blog - NETWORG
Sometimes we need to work with a variable inside a loop section. Whether it's a precomputation or just a helper variable.
Read more >JavaScript ES6: The forEach() Helper - Jonathan Dempsey
It's iteration over an array or list. In ES5, if we wanted to iterate over an array, we would make use of a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Don’t use the helper, use child components. Sorry that helper was just to help with very simple scenarios
Ah, gotcha! Thank you, will give it a try.