1

ページに次の HTML のインスタンスがいくつかあります。

<div class="input radio optional">
  <label class="collection_radio" for="warranty_selected_environments_attributes_1__destroy_false">
    <input checked="checked" class="radio optional" id="warranty_selected_environments_attributes_1__destroy_false" name="warranty[selected_environments_attributes][1][_destroy]" type="radio" value="false" />Yes
  </label>
  <label class="collection_radio" for="warranty_selected_environments_attributes_1__destroy_true">
    <input checked="checked" class="radio optional" id="warranty_selected_environments_attributes_1__destroy_true" name="warranty[selected_environments_attributes][1][_destroy]" type="radio" value="true" />No
  </label>
</div>

<div class="input numeric integer required">
  <label class="integer required" for="warranty_selected_environments_attributes_1_distance">Distance</label>
  <input class="numeric integer required" id="warranty_selected_environments_attributes_1_distance" name="warranty[selected_environments_attributes][1][distance]" required="required" size="50" step="1" type="number" />
</div>

このコードは simple_form gem で生成されているため、あまり制御できません。また、ネストされた属性フォームであるため、システム内の「環境」ごとに上記のコード セットの 1 つがあります。ラジオ グループが true か false かに応じて、テキスト入力の「距離」を表示および非表示にできるようにしたいと考えています。

ラジオ グループを視聴し、ページのどの「距離」ボックスを表示または非表示にするかを知る方法を見つけようとしています。この段階で考えられる最善の方法は、名前の値を使用し、最後の [_destroy] 部分を取り除き、[距離] を追加することです。上記のすべてが、リストされている環境ごとに div にラップされていることに注意してください。

長い HTML で申し訳ありません :)

4

1 に答える 1