Search code examples
ruby-on-railsinputsimple-form

how to stop a user reducing an integer input to less than 1


I have a simple form integer input and i wan't to stop the user from being able to reduce the amount below 1 when clicking on the arrows in the input (to the right).

Is this possible without javascript? The only information i can find is adding the min attribute to the input but that does not work.

<%= f.input :quantity, as: :integer %>

enter image description here


Solution

  • Following this should help you out.

    In your case, try:

    <%= f.input :quantity, as: :integer, input_html: { min: '0' } %>
    

    More reading: https://github.com/heartcombo/simple_form