2017-12-01 12 views
0

jQueryのクリスピーフォームの入力フィールドに、私はDjangoのクリスピーフォームを使用してい

<div id="div_id_code" class="form-group"> <label for="id_code" class="control-label col-lg-2 requiredField"> 
 
       Code<span class="asteriskField">*</span> </label> <div class="controls "> <input type="text" name="code" maxlength="50" class="textinput textInput form-control" required id="id_code" /> </div> </div> <div id="div_id_description" class="form-group"> <label for="id_description" class="control-label col-lg-2 requiredField"> 
 
       Description<span class="asteriskField">*</span> </label> <div class="controls "> <input type="text" name="description" maxlength="100" class="textinput textInput form-control" required id="id_description" /> </div> </div> <div id="div_id_qty" class="form-group"> <label for="id_qty" class="control-label col-lg-2 requiredField"> 
 
       Qty<span class="asteriskField">*</span> </label> <div class="controls "> <input type="number" name="qty" value="0" css-id="qty_id" class="numberinput form-control" required id="id_qty" /> </div> </div> <div id="div_id_price" class="form-group"> <label for="id_price" class="control-label col-lg-2 requiredField"> 
 
       Price<span class="asteriskField">*</span> </label> <div class="controls "> <input type="number" name="price" value="0" step="0.01" css-id="price_id" class="numberinput form-control" required id="id_price" /> </div> </div> <div id="div_id_total" class="form-group"> <label for="id_total" class="control-label col-lg-2 requiredField"> 
 
       Total<span class="asteriskField">*</span> </label> <div class="controls "> <input type="number" name="total" value="0" step="0.01" css-id="total_id" class="numberinput form-control" required id="id_total" /> </div>

を働いていません。いくつかの計算でqty_idprice_idをjQueryに使用すると、動作しません。 値フィールドに値を掛けた値を加算したい。

マイコード:

$(document).ready(function() { 
    $('#qty_id').on('change', function() { 
     $('#total_id').val($('#qty_id').val() * $('#price_id').val()); 
    }); 
    $('#price_id').on('change', function() { 
     $('#total_id').val($('#qty_id').val() * $('#price_id').val()); 
    }); 
}; 

forms.py

class ItemForm(forms.ModelForm): 
    def __init__(self, *args, **kwargs): 
     super(ItemForm, self).__init__(*args, **kwargs) 
     self.helper = FormHelper() 
     self.helper.label_class = 'col-lg-2' 
     self.helper.form_tag = False 
     self.helper.form_class = 'form-inline' 

     self.helper.layout = Layout(
       Field('code',), 
       'description', 
       Field('qty', id="qty_id"), 
       Field('price', id="price_id"), 
       Field('total', id="total_id"), 
       'employee', 
      ) 

    class Meta: 
     model = Item 
     fields = ('code', 'description', 'qty', 'price', 'total', 'employee',) 
+0

生成されたhtmlを表示します。 – aaron

+0

@aaron上記を参照してください。生成されたhtmlを追加しました。 –

答えて

0

は、私はすべて良いが今期待通りに働いているjQueryの準備方法でブラケットを逃したそれを考え出し

関連する問題