-
Notifications
You must be signed in to change notification settings - Fork 403
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
Numericality validator against other fields doesn't work as expected #687
Comments
@varvaray thanks for splitting this bug report I'm having troubles in understanding this step: " if i remove 1 of the fields" Could you please provide me something like Initial state:model validates :maximum_players,
allow_nil: true,
numericality: { only_integer: true, less_than_or_equal_to: 2147483647, greater_than_or_equal_to: :minimum_players }
validates :minimum_players,
allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: :maximum_players } view
Steps to reproduce:
Expected behaviour
Actual behaviourNo validation messages |
@tagliala Sorry for the late answer. I will point out only the things that are missing. Steps to reproduce: Insert 5 in :minimum_players Expected behaviour Minimum players should have error message like "Can't compare with empty field" Actual behaviour No validation messages ArgumentError in DFS::TournamentSchedulesController#create Extracted source (around line #58):
|
@tagliala another thing i wanted to discuss is the whole concept of 2 fields comparing. In the example above, when i'm performing step Insert 10 in :maximum_players I should have the message in the minimum_players field to be removed already. I did it myself in a bit of hacky way
and in .js $ ->
$('form').each ->
form = $(@)
form.find('input[data-compare-with]').each ->
input = $(@)
compare_with = $('#' + input.attr('id').replace(input.data('compare'), input.data('compare-with')))
input.on 'focusout', (e) ->
compare_with.trigger('change.ClientSideValidations')
compare_with.isValid(ClientSideValidations.forms[form.attr('id')].validators) So that if in any of 2 fields which are compared value changes, it triggers validation in another one, but i guess this can be implemented in the gem in that way or another. |
Steps to reproduce:
Expected behaviour:Validation on Actual behaviour:Validation on |
Unfortunately this could not be solved with the actual implementation of CSV or the solution is not naive. Example: Model attr_accessor :points_1, :points_2
validates :points_2, numericality: { greather_than: :points_1 }
There is no validation on Maybe this will be easier to fix if we switch to a model based / promise based implementation. |
@tagliala thanks for the explanation |
When using numericality: greater_than with other model attributes, if i remove 1 of the fields, it doesn't show any messages anymore, but when i try to submit, i'm getting server validation fail. I suppose it's better to reproduce server side behaviour for that case
validates :maximum_players,
allow_nil: true,
numericality: { only_integer: true, less_than_or_equal_to: 2147483647, greater_than_or_equal_to: :minimum_players }
validates :minimum_players,
allow_nil: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: :maximum_players }
The text was updated successfully, but these errors were encountered: