These are chat archives for dry-rb/chat

24th
Jan 2017
Adam Davies
@adz
Jan 24 2017 00:56

I have a situation where a field (answer) is dynamic… it can be a number, a date or one of a set of options…

rule(answer: [:answer, :kind, :optional, :options]) do |answer, kind, optional, options|
  (optional.false? > answer.filled?) &
    ((answer.filled? & kind.eql?('number')) > answer.number?) &
    ((answer.filled? & kind.eql?('date')) > answer.iso8601?) &
    ((answer.filled? & kind.eql?('options')) > answer.included_in?(options))
end

Seems to work ok, but the issue is that if blank, error messages pick up “must be a number, must be a date, must be one of …”.

is there a better way?

Tim Riley
@timriley
Jan 24 2017 03:00
Are those hints instead of hard error messages, @adz? In that case you could just choose not to pass them onto your user?
Adam Davies
@adz
Jan 24 2017 03:05
we’re using ‘messages’… is hints in by default?

i guess i’m trying to understand how the message is being generated.
I’m about to dive into source, but haven’t yet.

when we have (a & b) > c
and a is false, i’d expect the then to not fire
however, it appears we have validation messages on that

Tim Riley
@timriley
Jan 24 2017 03:07
yes, “hints” are generated for the latter
the intention with the hints is that in most cases it gives the user all the information they need to correct their input
otherwise they’d need several goes at entering their data before they discover/fix all the validation rules
Adam Davies
@adz
Jan 24 2017 03:08
yes — ran into this before… i like the idea, but here they’ll be wrong
Tim Riley
@timriley
Jan 24 2017 03:08
but you can filter hints out if you don’t want them
gimme a sec
Adam Davies
@adz
Jan 24 2017 03:08
nps
Tim Riley
@timriley
Jan 24 2017 03:08
yeah, that’s why they can be removed
Adam Davies
@adz
Jan 24 2017 03:08
Ok i’m on 0.10.4 dry-validaitons, and I see i can get errors/hints or messages for both
that’s one way...
Tim Riley
@timriley
Jan 24 2017 03:09
oh, great, you found it?
Adam Davies
@adz
Jan 24 2017 03:09
yeah, but in terms of hints, is there a way to structure the above to produce sensible ones?
Tim Riley
@timriley
Jan 24 2017 03:09
what output do you actually want?
Adam Davies
@adz
Jan 24 2017 03:10
well ‘kind’ is not user entered
it indicates the type
so depending on that, want to say “is not a number” OR “is not a date"
…but really it’s a learning opportunity for me :)
Tim Riley
@timriley
Jan 24 2017 03:11
Yeah, I kind of understand you but I’m fuzzy on the details
could you paste errors hash for what you get now, and then another for what you’d rather have?
Adam Davies
@adz
Jan 24 2017 03:12
i’ll try… there’s a few other issues too
Tim Riley
@timriley
Jan 24 2017 03:20
Might be worth throwing this into the discussion forum instead of chat, that way you’ll more likely get a fuller answer
Adam Davies
@adz
Jan 24 2017 03:23
oh — probably… is that discuss.dry-rb.org ? thnx
Tim Riley
@timriley
Jan 24 2017 03:24
yep!
Adam Davies
@adz
Jan 24 2017 03:32
Ok posted, with link to gist, pending moderation. Thanks
Tim Riley
@timriley
Jan 24 2017 03:36
And it’s up
Adam Davies
@adz
Jan 24 2017 03:47
thx