SORU
14 NİSAN 2009, Salı


Raylar radyo düğmesi için bir etiket formu

Benim sorum this onebenzer ama Rails uygulaması için.

Bazı radyo düğmeleri ile bir form var, ve onlarla etiketler ilişkilendirmek ister. label form Yardımcısı sadece bir parametre olarak bir form alanı alır, ama bu durumda tek bir form alanı için birden fazla radyo düğmesi var. Bunu yapmak için tek yolu elle bir etiket, sert radyo düğmesi için otomatik oluşturulan KİMLİK kodlama oluşturmaktır. Herkes bunu yapmak için daha iyi bir yol biliyor mu?

Örneğin:

<% form_for(@message) do |f| %>
    <%= label :contactmethod %>
    <%= f.radio_button :contactmethod, 'email', :checked => true %> Email
    <%= f.radio_button :contactmethod, 'sms' %> SMS
<% end %>

Böyle bir şey üretir:

<label for="message_contactmethod">Contactmethod</label>
<input checked="checked" id="message_contactmethod_email" name="message[contactmethod]" value="email" type="radio"> Email
<input id="message_contactmethod_sms" name="message[contactmethod]" value="sms" type="radio"> SMS

Ben ne istiyorum:

<input checked="checked" id="message_contactmethod_email" name="message[contactmethod]" value="email" type="radio"><label for="message_contactmethod_email">Email</label>
<input id="message_contactmethod_sms" name="message[contactmethod]" value="sms" type="radio"> <label for="message_contactmethod_sms">SMS</label>

CEVAP
5 Kasım 2010, Cuma


:value 9 ** seçeneğine geçen etiket etiket for öznitelik karşılık gelen kimliği olarak aynı olduğundan emin olun. radio_button

<% form_for(@message) do |f| %>
  <%= f.radio_button :contactmethod, 'email' %> 
  <%= f.label :contactmethod, 'Email', :value => 'email' %>
  <%= f.radio_button :contactmethod, 'sms' %>
  <%= f.label :contactmethod, 'SMS', :value => 'sms' %>
<% end %>

ActionView::Helpers::FormHelper#label bkz

:radio_button etiketleri için etiket hedef için tasarlanmış bir değer seçenek

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • CorridorDigital

    CorridorDigi

    17 Mayıs 2010
  • InfoPuppet

    InfoPuppet

    15 Kasım 2011
  • SketchBookPro

    SketchBookPr

    6 Mayıs 2009