L
L
lavezzi12015-09-02 13:00:40
JavaScript
lavezzi1, 2015-09-02 13:00:40

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

4 answer(s)
E
Eugene Burmakin, 2015-09-02
@Freika

Validate on the front end, jquery is more than enough for that

R
Roman Mirilaczvili, 2015-09-02
@2ord

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

T
TyzhSysAdmin, 2015-09-02
@POS_troi

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.

D
dev2expert, 2015-09-02
@dev2expert

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 question

Ask a Question

731 491 924 answers to any question