Min value for input in Simple Form

前端 未结 4 924
耶瑟儿~
耶瑟儿~ 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:30

    For @georgebrock's answer to work, in simple_form.rb (or whatever name you do use, could be simple_form_bootstrap.rb) you need to change:

    b.optional :min_max
    

    To:

    b.use :min_max
    

    For the wrapper that's being used to draw the input.

    The "optional" means simple form will use the component but will not lookup automatically, letting you to specify :min and :max params on the input manually.

提交回复
热议问题