From 9fe8f98a173018592fbb9722df3ab63e310ecfcf Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 7 Apr 2023 09:53:46 +0200 Subject: [PATCH] refactor(routing): add id to option to help morph --- app/components/procedure/routing_rules_component.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/components/procedure/routing_rules_component.rb b/app/components/procedure/routing_rules_component.rb index 7a92dbd30..bfce00008 100644 --- a/app/components/procedure/routing_rules_component.rb +++ b/app/components/procedure/routing_rules_component.rb @@ -32,7 +32,10 @@ class Procedure::RoutingRulesComponent < ApplicationComponent def value_tag(targeted_champ, value, row_index) select_tag( 'value', - options_for_select(values_for_select(targeted_champ), selected: value.to_json), + options_for_select( + values_for_select(targeted_champ, row_index), + selected: value.to_json + ), id: input_id_for('value', row_index) ) end @@ -67,8 +70,10 @@ class Procedure::RoutingRulesComponent < ApplicationComponent .map { |tdc| [tdc.first, constant(tdc.first).to_json] } end - def values_for_select(targeted_champ) - empty_target_for_select + available_values_for_select(targeted_champ) + def values_for_select(targeted_champ, row_index) + (empty_target_for_select + available_values_for_select(targeted_champ)) + # add id to help morph render selected option + .map { |(libelle, json)| [libelle, json, { id: "#{row_index}-option-#{libelle}" }] } end def input_id_for(name, row_index)