2017-09-26 85 views
0

我申請我的產品形式的模板中選擇價值,我會知道汽車在我的編輯形式汽車在形式

<div class="btn-group" data-toggle="buttons"> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="0"/> Aucune 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="1"/> 1 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="2"/> 2 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="3"/> 3 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="4"/> 4 
     </label> 
     <label class="btn btn-danger" style="margin-right: 10px;"> 
      <input id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="5"/> 5 et + 
     </label> 
     </div> 

如何選擇定義值。如果我的產品的價值是1我想在1

+0

在你想要的輸入類型上使用'selected'屬性? –

回答

1

一個活性按鈕可以使用checked屬性,從數據庫/控制器樞轉關值的,如下所示:

<input <%= "checked" if product == 1 %> id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="1"/> 
<input <%= "checked" if product == 2 %> id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="2"/> 
<input <%= "checked" if product == 3 %> id="bien_nb_piece_true" name="bien[nb_piece]" type="radio" autocomplete="off" value="3"/> 

等。