2011-03-30 62 views
1

我一直在試圖隱藏使用Django api在模型類中定義的隱藏字段的標籤。該模型的CRUD操作由Django管理。如何隱藏隱藏字段的標籤

我的模型是

class RackForm(django.forms.ModelForm): 

    def __init__(self, *args, **kwargs): 
    self.fields['racktypeid'].widget = \ 
     forms.HiddenInput(attrs={'styles': 'display:none;'}) 
    ..... other initialization 

下面

<div class="form-row racktypeid"> 


      <div> 

        **<label for="id_racktypeid" class="required">Rack Type:</label>** 

         **<input styles="display:none;" name="racktypeid" value="3" onchange="changeRackType(this);" type="hidden" id="id_racktypeid" />** 




        <p class="help">The physical type of rack as defined in the rack type list</p> 

      </div> 

    </div> 

領域已被隱藏,但沒有相關的標籤生成的HTML源中給出。我甚至嘗試過使用jQuery。我可能是錯誤的語法。如果我是,請糾正我,如果我錯了。

$(document).ready(function() { 
    // Hide label for RackForm rack type id label. 
    $('#id_racktypeid, label[for="#id_racktypeid"]').hide() 
    $('#id_racktypeid, label[for="#id_racktypeid"]').parent().hide() 
    }); 
}); 

沒有任何選項成功。我需要隱藏隱藏字段的標籤嗎?

更新:最終我選擇隱藏整個div標記。

+0

不包括在標籤中#[爲=「...」]選擇。 – 2011-03-30 01:52:26

+0

是的,#太多了。此外,這可以使用純CSS:label [for =「racktypeid」] {display:none;} – arie 2011-03-30 07:10:41

+0

@arie:我需要爲此創建一個css文件嗎?我很抱歉,但我不明白。 – Kartik 2011-04-03 19:52:54

回答