bootstrap-ruby / bootstrap_form

Official repository of the bootstrap_form gem, a Rails form builder that makes it super easy to create beautiful-looking forms using Bootstrap 5.
MIT License
1.64k stars 352 forks source link

If an input is required then the input does nog always get the required element #604

Closed CharlieWinkwaves closed 2 years ago

CharlieWinkwaves commented 2 years ago

For example in the demo application email is a required field. validates :email, presence: true

<div class="form-group row"><label class="col-form-label col-sm-2 required" for="user_email">Email address</label><div class="col-sm-10"><input placeholder="Enter Email" class="form-control" type="email" name="user[email]" id="user_email"><small class="form-text text-muted">We'll never share your email with anyone else</small></div></div> Then the label has an element required but the input has not. This means that when a screenreader reads the form is is not mentioned that the input is required.

If an input got the option required: true eq form.text_area :misc, required: true then the input field did get a required element

In BootstrapForm::FormGroupBuilder.form_group_builder_options and BootstrapForm::FormGroupBuilder.form_group_required. there is something done with required but it does not work how I expected it to work.

I added required and aria-required to all the input types, except the select. Something in the BootstrapForm::Inputs::Select.select_with_bootstrap, from the form_group_builder it does get the options. But when calling select_without_bootstrap(method, choices, options, html_options, &block) with the correct options it does not return required or aria-required.

I will add a PR with my changes