Situation
Have a simple form which abstract parts i post below:
<div class="form-group">
<%= f.label :net %>
<div class="input-group w-50">
<%= f.text_field :net,
required: true,
class: 'form-control text-right' %>
<div class="input-group-append">
<span class="input-group-text" style="width: 40px;">€</span>
</div>
</div>
</div>
&
<div class="form-group">
<%= f.label :vat_rate, t('in_invoice.form.vat_rate') %>
<%= render 'home/shared/standard_vat' %>
<div class="input-group w-50">
<%= f.text_field :vat_rate,
required: true,
class: 'form-control text-right' %>
<div class="input-group-append">
<span class="input-group-text" style="width: 40px;">%</span>
</div>
</div>
</div>
with model:
...
validates :net, :number, :vat_rate, presence: true
validates :net, numericality: { greater_than: 0}
validates :vat_rate, numericality: { only_integer: true, greater_than_or_equal_to: 0}
validates :net, numericality: true
...
My problem
I want to put an asterisk on the vat_rate (Screenshot: "VAT-Rate in %") label in the form. But for some reason it appears only on the :net and the :number field despite making them equal (e.g. removing the partial in between, includind presence validation) as you can see on the screenshot
. (I think it doesn't matter but the form is a simple_form initialized with simple_form_for)
Asterisk is added by simple form. When you pass text as a second argument you override everything. If you want to keep the
*pass text as an option:https://github.com/heartcombo/simple_form/blob/v5.3.0/lib/simple_form/form_builder.rb#L319
If your
simple_formdoesn't look like this, you're missing the point of simple form:You should configure your inputs only once and just use
inputhelper:https://github.com/heartcombo/simple_form/tree/main#configuration
For example: