refactor(condition): use dom_id with stable_id

This commit is contained in:
Paul Chavard 2022-07-13 15:38:43 +02:00
parent 0adfd92213
commit 98a0bc8c71
3 changed files with 8 additions and 3 deletions

View file

@ -1,4 +1,4 @@
.flex.justify-start.section{ id: "conditions_type_de_champ_#{@tdc.stable_id}" }
.flex.justify-start.section{ id: dom_id(@tdc.stable_self, :conditions) }
= form_with url: admin_procedure_condition_path(@procedure_id, @tdc.stable_id), method: :patch, class: 'form width-100' do |f|
.conditionnel.mt-2.width-100
.flex

View file

@ -360,6 +360,11 @@ class TypeDeChamp < ApplicationRecord
end
end
def stable_self
OpenStruct.new(to_key: [stable_id],
model_name: OpenStruct.new(param_key: model_name.param_key))
end
private
DEFAULT_EMPTY = ['']

View file

@ -1,8 +1,8 @@
- rendered = render @condition_component
- if rendered.present?
= turbo_stream.morph "conditions_type_de_champ_#{@tdc.stable_id}" do
= turbo_stream.morph dom_id(@tdc.stable_self, :conditions) do
- rendered
end
- else
= turbo_stream.remove "conditions_type_de_champ_#{@tdc.stable_id}"
= turbo_stream.remove dom_id(@tdc.stable_self, :conditions)