Min value for input in Simple Form

前端 未结 4 818
耶瑟儿~
耶瑟儿~ 2021-02-18 21:42

I want to create a simple money input with SimpleForm.

The money field should have a minimum value of 0, so that a user cannot enter a value less than 0.

However

4条回答
  •  别跟我提以往
    2021-02-18 22:06

    The answer of @alexander-s is normally right.

    However, I had an issue with simple_form.rb being run over by simple_form_bootstrap.rb that they instruct you NOT to change. It lists b.optional :min_max many places.

    Instead of the global setting of b.use :min_max mentioned by @alexander-s, I used

    <%= f.input :amount, min_max: true %>
    

    This is better as it reuses the min number set in your model.

提交回复
热议问题