[Question]: Access other model properties in validation function
See original GitHub issueIs your feature request related to a problem? Please describe. I store my validation rules in separate file. When I’m trying to base validation function on other model property - I’m unable to do it.
Describe the solution you’d like According to doc I was expecting that I should get model as a second parameter. AFAIK I get Vue instance. I’m unable to access other model properties as stated in doc. I’d like use vuelidate as stated in linked doc.
Additional context “@vuelidate/core”: “^2.0.0-alpha.25”, “@vuelidate/validators”: “^2.0.0-alpha.21”, “vue”: “^3.2.6”,
Simplified example rules.ts
const requireIfActive = (value: string, vm: any) => {
// how to access model property active?
// vm.active is undefined
return false
}
export default {
name: {
required: requireIfActive
}
}
TheComponent.vue
<script setup lang="ts">
import rules from './rules'
const record = ref({
active: false,
name: null,
})
useVuelidate(rules, record, { $lazy: true })
}
Is there anything I’m doing wrong?
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (15 by maintainers)
Top Results From Across the Web
c# - Custom validation method that accesses other model ...
The validation annotation I'm writing will be applied to the Wheelchair property, and I need to access the TimetableId property from within my ......
Read more >Restrict data input by using validation rules
Validations rules help you check data as it is added to your Access desktop database which improves accuracy and consistency of data entry....
Read more >Frequently Asked Questions | Ajv JSON schema validator
Why Ajv assigns errors as a property of validation function (or instance) instead of returning an object with validation results and errors?
Read more >Model instance reference
To create a new instance of a model, instantiate it like any other Python class: ... or to do validation that requires access...
Read more >The Complete Guide To Validation In ASP.NET MVC 3 - Part 2
We will include functionality to output HTML5 data-* attributes for use with ... This (among other things) gives us access to the whole...
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
I am not sure I get what you need here. As for the
forEach
helper, I can pass the current iterated object to a validator, as as second parameter. Is that something that you feel would help you? For example:In order to help you more, I would need to see code 😕
@dobromir-hristov OMG - I’m taking back everything what I’ve just written!
Couple of minutes later and it works like a charm! It looks like I get a problem with npm update or so, because now I get the behavior I was looking for.
Sorry for inconvenience.
Thanks!