2016-09-08 10 views
0

私はモーダルでDjangoフォームをレンダリングしています。名前フィールドは正常に動作しますが、アクティブなクラスをオンにしている場合でも2つの選択フィールドにオプションが表示されます。下モーダル化モーダルを選択して表示しない

$(document).ready(function(){ 
$('.modal-trigger').leanModal(); 
$('select').material_select(); 
    }); 

検査官が要素

<div class="select-wrapper"><span class="caret">▼</span> 
<input type="text" class="select-dropdown" readonly="true" data-activates="select-options-2de779c1-46cd-3271-5da4-889766247340" value="Silver"><select id="id_subscriber_status" name="subscriber_status" class="initialized"> 
    <option value="-1">Inactive</option> 
    <option value="0">Free</option> 
    <option value="1" selected="selected">Silver</option> 
    <option value="2">Gold</option> 
    <option value="3">Platinum</option> 
    </select></div> 

にどのように見えるかをモデルフォーム余分明確にするために

class StoreForm(forms.Form): 
    name = forms.CharField(required=True) 
    store_size = forms.ChoiceField(widget=forms.Select(), 
           choices=models.SIZE_CHOICES, initial='1', required=True) 
    subscriber_status = forms.ChoiceField(widget=forms.Select(), 
             choices=models.SUBSCRIBER_LEVEL, initial='1', 
             help_text="You can always downgrade or upgrade through your console") 

    class Meta: 
     model = models.Store 

、なぜ読み取り専用ノーアイデアで

<div id="modal1" class="modal"> 
    <div class="modal-content"> 
     <h4>Create a Store</h4> 
     <form action="/" method="post"> 
      {% csrf_token%} 
      {% for field in form %} 
       <div class="input-field"> 
        {{ field.errors }} 
        {{ field.label_tag }} <br>{{ field }} 
       </div> 
      {% endfor %} 

      <button class="btn" type="submit">Create!</button> 
     </form> 
    </div> 
    <div class="modal-footer"> 
     <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a> 
    </div> 
    </div> 

スクリプト私は設定していないので、真実ですそれはそうである。私はコンソール内のすべてのattrを手に入れて、Z-Indexやオーバーフローなどのスタイルを追加しようとしましたが、まだ何もしていませんでした。

ありがとうございました

答えて

1

多分あなたに役立つでしょう。

class StoreForm(forms.Form): 
    class Meta: 
     model = models.Store 
     fields = ['name','store_size','subscriber_status'] 
     widgets = { 
      'name':forms.TextInput(attrs={'placeholder': 'Name'}), 
      'store_size':forms.SelectMultiple(choices = models.SIZE_CHOICES,attrs={'multiple':'multiple','data-placeholder': 'Select Size'}), 
      'subscriber_status':forms.SelectMultiple(choices = models.SUBSCRIBER_LEVEL,attrs={'multiple':'multiple','data-placeholder': 'Select Status'}) 
     } 
関連する問題