Hi
I'm experiencing a problem with the optional extensions. I want to enable the :min_max extension in the initializer and it does not seem to add the attributes unless I use min_max: true on the input directly. I'm trying to see if I've missed anything and from the documentation and Google searches, it does not appear that I have.
I completely reset config/initializers/simple_form.rb and I'm still not getting the desired behavior.
Wrapper
config.wrappers :default, class: :input,
hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :minlength
b.optional :pattern
b.use :min_max
b.optional :readonly
b.use :label_input
b.use :hint, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }
end
Model:
class VitalityHealthCheck::Adult
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :vitality_check_medical_systolic
validates :vitality_check_medical_systolic,
presence: true,
numericality: { greater_than_or_equal_to: 70, less_than_or_equal_to: 240 }
end
View example (slim):
= simple_form_for @note.vhc,
as: :vitality_health_check_report,
method: :patch,
remote: true,
url: consultation_note_vitality_health_check_path(@note.consultation, @note.note) do |f|
= f.input :vitality_check_medical_systolic
Generated HTML:
<input class="string required" type="text" name="vitality_health_check_report[vitality_check_medical_systolic]" id="vitality_health_check_report_vitality_check_medical_systolic">
I expect the following HTML to be rendered:
<input class="string required" min="70" max="240" type="text" name="vitality_health_check_report[vitality_check_medical_systolic]" id="vitality_health_check_report_vitality_check_medical_systolic">
Could you please provide us a sample application that reproduces the issue in isolation?
That would help us find the issue.
Thank you for the response @feliperenan, I will get right on that
Here you go @feliperenan. I've added all the information in the README
Hi @franks921
After some investigation I figured out that it only works with numeric inputs which makes sense for me. So in your case, all you need to do is providing as: :integer option to your input to get it working from the wrapper.
We could improve the documentation being more clear about it somewhere. Feel free to open a pull-request for that :wink:. For now, I'm going to close this one since it seems working as expected.
Thanks for the issue and reproduced app, it helped a lot to understand what's going on :muscle:
Thank you very much for the speedy response on this @feliperenan. I will open a PR for this :)
Most helpful comment
Here you go @feliperenan. I've added all the information in the README
https://github.com/franks921/simple_form_debug