writing a rule using multiple fields
See original GitHub issueGiven the following data structure
case class Family(name: String, children: Set[Child], mainPet: Pet, otherPets: Seq[Pet])
object Family {
implicit val validations: Validator[Family] = Validator
.derived[Family]
.rule[String](_.name, _.nonEmpty, "is required")
}
Is there a way to write a rule that combines more than one field? E.g.
mainPet
can’t be the same as one of theotherPet
smainPet
name can’t be the same as one of thechildren
s’ name
I tried writing a selector
that would map a tuple, e.g. Family => (String, Pet)
, but it looks like the macro won’t support that.
val familyNameCantBeSameAsMainPet = (pair: (String, Pet)) => pair._1 != pair._2.name
val nameAndMainPetSelector = (family: Family) => (family.name, family.mainPet)
...
...
.rule[(String, Pet)](nameAndMainPetSelector, familyNameCantBeSameAsMainPet, "testing tuple selector")
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to Add multiple fields to a section and apply rule ... - MSDN
- Insert a table to add fields or drag and drop the fields into the section. - Click on where it says "Section"....
Read more >Multiple fields under a single validation rule - IdeaExchange
Users should be able to create validation rules for multiple fields on a page layout under one rule instead of having to create...
Read more >validation rules on multiple fields - Salesforce Stack Exchange
I have written this simple validation rule that will throw an error when the user enters less than 2 characters in Name and...
Read more >How Do You Do Conditional Formatting with 2 Conditions?
1 Column, 2 Rules, 2 Conditions · Select the data range containing the invoice values, click on “Conditional Formatting” available on “Home” tab....
Read more >How to Create Validation Rules with Multiple Conditions
Salesforce #SalesforceSupport #SalesforceHowToAfter watching this screencast the user will be able to learn how to create validation rules ...
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 FreeTop 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
Top GitHub Comments
We can throw this one on the roadmap as a feature request for custom naming. Closing.
Well, empty path here means root path. So in this context I believe it’s correct as for such validation the problem is due to invalid relationship between different field values.
When you have Family nested (or in a collection), you get your family-level errors prefixed with non empty path.
If you really need to, you can assign this error to a single specific field (name? using 3 arg rule). Other options are not supported currently.