Link description and error to form fields
This commit is contained in:
parent
6256b5f336
commit
56554aef4b
6 changed files with 10 additions and 6 deletions
|
@ -2,10 +2,10 @@
|
|||
|
||||
module Dsfr
|
||||
class InputStatusMessageComponent < ApplicationComponent
|
||||
def initialize(errors_on_attribute:, error_full_messages:, describedby_id:, champ:)
|
||||
def initialize(errors_on_attribute:, error_full_messages:, champ:)
|
||||
@errors_on_attribute = errors_on_attribute
|
||||
@error_full_messages = error_full_messages
|
||||
@describedby_id = describedby_id
|
||||
@error_id = champ.error_id
|
||||
@champ = champ
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.fr-messages-group{ id: @describedby_id }
|
||||
.fr-messages-group{ id: @error_id, aria: { live: :assertive } }
|
||||
- if @error_full_messages.size > 0
|
||||
%p{ class: class_names('fr-message' => true, "fr-message--#{@errors_on_attribute ? 'error' : 'valid'}" => true) }
|
||||
= "« #{@champ.libelle} » "
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
= @form.label @champ.main_value_name, id: @champ.labelledby_id, for: @champ.input_id, class: 'fr-label' do
|
||||
- render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at
|
||||
- if @champ.description.present?
|
||||
.fr-hint-text= render SimpleFormatComponent.new(@champ.description, allow_a: true)
|
||||
.fr-hint-text{ id: @champ.describedby_id }= render SimpleFormatComponent.new(@champ.description, allow_a: true)
|
||||
- elsif @champ.legend_label?
|
||||
%legend.fr-fieldset__legend.fr-text--regular.fr-pb-1w{ id: @champ.labelledby_id }= render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at
|
||||
- if @champ.description.present?
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
|
||||
= render champ_component
|
||||
|
||||
= render Dsfr::InputStatusMessageComponent.new(errors_on_attribute: champ_component.errors_on_attribute?, error_full_messages: champ_component.error_full_messages, describedby_id: @champ.describedby_id, champ: @champ)
|
||||
= render Dsfr::InputStatusMessageComponent.new(errors_on_attribute: champ_component.errors_on_attribute?, error_full_messages: champ_component.error_full_messages, champ: @champ)
|
||||
|
|
|
@ -1 +1 @@
|
|||
= @form.text_field(:value, input_opts(id: @champ.input_id, required: @champ.required?, aria: { describedby: @champ.describedby_id }))
|
||||
= @form.text_field(:value, input_opts(id: @champ.input_id, required: @champ.required?, aria: { describedby:"#{@champ.describedby_id} #{@champ.error_id}" }))
|
||||
|
|
|
@ -179,6 +179,10 @@ class Champ < ApplicationRecord
|
|||
"#{html_id}-describedby_id"
|
||||
end
|
||||
|
||||
def error_id
|
||||
"#{html_id}-error_id"
|
||||
end
|
||||
|
||||
def log_fetch_external_data_exception(exception)
|
||||
update_column(:fetch_external_data_exceptions, [exception.inspect])
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue