Simple_form: minlength defaults to limit of column

Created on 15 Dec 2017  路  3Comments  路  Source: heartcombo/simple_form

Environment

  • Ruby 2.2.7
  • Rails 4.2
  • Simple Form 3.5.0

Current behavior

When the component minlength is used and there are string columns that have no validation, the limit of the column is used as minlength.

Expected behavior

The minlength attribute should not be set (or set to 0) if a column has no validation that forces a min length.

Fix

the fix is pretty easy:
in lib/simple_form/components/minlength.rb line 6
delete the ' || limit'
which seems to be a left over of copying from maxlength.rb.

This also fixes #1496

Most helpful comment

I created a minimal rails app (5.2, ruby 2.4) with just one table and one attribute:
form_sample.zip

If you edit "Shrek" (or add a new Ogar), you can see that the input field has
minlength=255 maxlength=255

All 3 comments

Hi @mameier Thanks for the report.

Could you provide a sample application that reproduces the error?

I created a minimal rails app (5.2, ruby 2.4) with just one table and one attribute:
form_sample.zip

If you edit "Shrek" (or add a new Ogar), you can see that the input field has
minlength=255 maxlength=255

I submitted a pull request .
This fix works for me.

Was this page helpful?
0 / 5 - 0 ratings