2012-03-15 20 views
1

私はrail 3.2.2でsimple_form gemを使用しており、HABTM関連のchecboxを設定しようとしています。Rails Simple_form gemとjQuery Mobileチェックボックス

監視があり、多くのシナリオとヴィーカのその逆に属します。チェックボックスのセットが自動的に使用して、簡単なフォームを使用して

、私がすることができ、出力:

= f.association :scenarios, as: :check_boxes 

これは、次のような出力生成します。しかし

<div class="checkbox"> 
    <label class="checkbox"> 
    <div class="ui-checkbox"> 
     <input class="check_boxes optional" id="monitoring_scenario_ids_1" name="monitoring[scenario_ids][]" type="checkbox" value="1"> 
     </div> 
    Haraam Meat Found</label> 
    <input name="monitoring[scenario_ids][]" type="hidden" value=""> 
</div> 

を、jQueryのモバイルだけでスタイルが、それならば、それを認識します

<input type="checkbox" name="checkbox-1" id="checkbox-0" class="custom" /> 
<label for="checkbox-0">I agree</label> 

誰でもこの方法を知っていますか?

それはハックの少しですが pagecreateイベントが発生するとき、あなたのHTMLを再整理することができ

答えて

1

変更で:inlineから:nestedからconfig.boolean_styleあなたconfig/initializers/simple_form.rbこれらの行でわかるようにhttps://github.com/plataformatec/simple_form/blob/master/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt#L94-98

+0

これは機能しますが、グループ化されたチェックボックスとしては表示されません。これを行う方法に関するアイデア? – Ammar

+0

すべてのcollection_check_boxesはインラインで表示されます。それは起こっていないのですか? – rafaelfranca

+0

これで、有効なjQuery Mobileチェックボックスとして表示されます。ただし、チェックボックスはグループ化されていません。 [docsページ](http://jquerymobile.com/demos/1.1.0-rc.1/docs/forms/checkboxes/)で私が何を意味するのかを見ることができます。私が得たのは最初の例ですが、私が探しているのは、縦にグループ化されたチェックボックスですか? – Ammar

0

:ここ

//wait for the page to be created 
$(document).delegate('[data-role="page"]', 'pagecreate', function() { 

    //loop through each of the `div.checkbox` elements 
    $.each($(this).find('div.checkbox'), function (index, element) { 

     //cache the label for this `div.checkbox` element and the form inputs 
     var $label = $(this).children('label').attr('for', $(this).find('input[type="checkbox"]')[0].id), 
      $inputs = $label.find('input'); 

     //append the inputs at the same level as the label, 
     //then select the checkbox and initialize a checkbox widget 
     $label.parent().append($inputs).children('input[type="checkbox"]').checkboxradio(); 
    }); 
});​ 

はデモです: http://jsfiddle.net/vAjDn/2/

関連する問題