Answer the question
In order to leave comments, you need to log in
How to restrict data input in input?
Good afternoon. Application on RoR. There are two fields, let's say if a person entered 500 in the first field, then you need to make sure that he cannot enter more than 500 in the second. How to implement this and what is better, in RoR or Jquery? Maybe it's possible through validation in ror?
Answer the question
In order to leave comments, you need to log in
You need to write the logic / rules for field validation yourself. Google: "jquery form validation"
And in RoR it's better to play it safe by specifying
validates :some_column, less_than_or_equal_to: 500 in the model
You will receive all the data from the form in a POST request, nothing prevents you from checking the .size of both fields.
You can also check on the frontend - as a preliminary check.
On the backend, anyone can check the same - in case of disabled javascripts, etc.
Do the validation of the second field based on the entered data using js.
Then, on the server, you validate all the fields again, in particular, check that the length of the second field is no more than the first, if the validation does not pass, then return the form with a message about incorrect data and ask to fill it out again.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question