heartcombo / simple_form

Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
http://blog.plataformatec.com.br/tag/simple_form
MIT License
8.21k stars 1.31k forks source link

allow_blank true doesn't work #1803

Closed charlie-goldenowl closed 2 months ago

charlie-goldenowl commented 1 year ago

Precheck

https://github.com/heartcombo/simple_form/blob/86429bceb950096df3c29616f31bd5a5ce706c06/lib/simple_form/helpers/required.rb#L22 how we can remove required class for this case bellow

validates :xxx, presence: true, allow_blank: true

Environment

Current behavior

Include code samples, errors, steps to reproduce the error and stacktraces if appropriate.

Will be even more helpful if you provide a sample application or a test case that reproduces the error.

Expected behavior

nashby commented 2 months ago

Hey @charlie-goldenowl! We don't check for allow_blank: true in required helper because using allow_blank with presence validation doesn't make much sense (I'm not even sure this combination works properly). It's usually used with something like length validation:

validates :title, length: { is: 5 }, allow_blank: true