question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

writing a rule using multiple fields

See original GitHub issue

Given 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 the otherPets
  • mainPet name can’t be the same as one of the childrens’ 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andyczerwonkacommented, Nov 3, 2020

We can throw this one on the roadmap as a feature request for custom naming. Closing.

1reaction
krzemincommented, Nov 2, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found