Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dry Validation hints are included in Reform::Contract::Errors #444

Open
grizzlydev opened this issue Aug 25, 2017 · 2 comments
Open

Dry Validation hints are included in Reform::Contract::Errors #444

grizzlydev opened this issue Aug 25, 2017 · 2 comments
Labels
Milestone

Comments

@grizzlydev
Copy link

Complete Description of Issue

Reform/ Dry integration takes the whole Dry::Validation::Result#messages (hints + errors), not just errors. Consequently hints are presented indistinguishable from actual errors. If you have two predicates which validate the same nature of an input (e.g. less than + greater than on an int) this leads to a bad user experience - users are told something is failing when it is not.

Steps to reproduce

  class PersonForm < Reform::Form
    property :name

    property :age

    validation do 
      required(:name).filled
      
      required(:age).filled(:int?, gt?: 18, lt?: 70)
    end 
  end
  PersonModel = Struct.new(:name, :age)
  form = PersonForm.new(PersonModel.new)
  result = form.validate({
    name: 'joe bloggs',
    age: 17
  })

Expected behavior

Tell us what should happen

# result.errors is {:age=>["must be greater than 18"]}

Actual behavior

Tell us what happens instead

# result.errors is {:age=>["must be greater than 18", "must be less than 70"]}

System configuration

Reform version:2.2.4

Full Backtrace of Exception (if any)

N/A

@apotonick apotonick added this to the v 2.3 milestone Aug 29, 2017
@apotonick
Copy link
Member

Cool, I finally understood the difference and what's a hint, now!

@fran-worley
Copy link
Collaborator

@apotonick if you look back at the old code I put together for 2.3.1 I had a handle for this.

We have to be careful how we do it as if you run separate calls to dry-v's error messages object (say to get errors and hints separately) it'll build the errors twice.

@emaglio emaglio modified the milestones: v 2.3, v2.2.5 Jul 14, 2019
@emaglio emaglio modified the milestones: v 2.3, 3.0 Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants