How to use requiredIf?
See original GitHub issueFirst question
Probably I’ve not understood a basic thing: must requiredIf
return true
to indicate that the field itself is required, or true if the validation is successfully passed?
for example: when the password is not mandatory, must my function return false (because is not mandatory), or true (because the ‘require’ validation has been passed) ?!?!
Second question
What is supposed to be the param of requiredIf?
I’ve a form used both for creating new users and for editing existing users.
If creating, the computed method isNewUser
returns true.
If editing, it returns false,
I’m trying to implement the rule that password is mandatory only if isNewUser.
computed: {
isNewUser() {
return this.$store.getters["customers/getIsNewUser"];
}
},
validations: {
....
new_password: {
minLength: minLength(8),
sameAs: sameAs("repeat_new_password"),
required: requiredIf(function(model) {
console.log("isNewUser", this.isNewUser);
console.log("model", model);
console.log("model.new_password", model.new_password);
const esit =
!this.isNewUser ||
(this.isNewUser && model.new_password);
console.log("esit", esit);
return esit;
})
}
...
}
This is my console output when inserting a new user.
What kind of what is the model
param?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
asp.net mvc 3 - RequiredIf Conditional Validation Attribute
Tips To Get The Javascript Code Part Work · 1- put the code in a new js file (ex:requiredIfValidator.js) · 2- warp the...
Read more >Required If Validation - MSDN - Microsoft
I would like UploadFile to be required if @Model.Filename is null . Of course I can make it required all the time in...
Read more >NET 6.0 Blazor custom validation - YouTube
.NET 6.0 Blazor custom validation | RequiredIf validation in Blazor.
Read more >[Solved] How to use data annotation to check for two values.
I am using .NET Core for the solution and have seen exampled for RequireIF but it only checks one field. I need multiple...
Read more >MVC 3 RequiredIf validator for multiple values
... using DataAttributes... Problem for me: I needed the field to be Required if the selected value in my dropdownlist was either 1,...
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
@realtebo here you go mate. https://jsfiddle.net/dobromir/1xe7mv3h/4/
Hi @dobromir-hristov thanks for the fiddle, i have been playing with vuelidate and its awesome. I however have a blocker… what if the field in question needs to be validated by another field of the model. I have this validation
Basically in my object model track it has a prop called
is_gold_price
which is a check button that unhides and hides the gold price field. I wish to be able to access each instance of theis_gold_price
, So the field is to be required if an only if the is_gold_price has been toggled on which is for some particular track. How can one access the props of each? A little help would be appreciated thanks