Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 模态形式初始场_Jquery_Django - Fatal编程技术网

Jquery 模态形式初始场

Jquery 模态形式初始场,jquery,django,Jquery,Django,在我的应用程序中,有一个用于更新项目的表单 用户使用下拉字段更新它。如果下拉列表中没有要求的值,他可以添加自己的值 这是通过弹出引导模式表单完成的。问题是,如果提交了模式表单,用户将被重定向到表单视图,但我们已经输入的所有值都将消失 我不是在寻找现成的解决方案,而是一个如何制作的提示,因为我正在学习,现在我想知道应该如何正确地完成 点击“新人”打开模式表单。我不想两次使用选择附属公司,因为一个人属于附属公司 如果添加了新用户,则用户填写的所有值都将消失,因为我正在从模式重定向到用户开始更新的点

在我的应用程序中,有一个用于更新项目的表单

用户使用下拉字段更新它。如果下拉列表中没有要求的值,他可以添加自己的值

这是通过弹出引导模式表单完成的。问题是,如果提交了模式表单,用户将被重定向到表单视图,但我们已经输入的所有值都将消失

我不是在寻找现成的解决方案,而是一个如何制作的提示,因为我正在学习,现在我想知道应该如何正确地完成

  • 点击“新人”打开模式表单。我不想两次使用选择附属公司,因为一个人属于附属公司
  • 如果添加了新用户,则用户填写的所有值都将消失,因为我正在从模式重定向到用户开始更新的点
  • 当用户选择新的人员表单下拉列表时,模式表单打开:

    jQuery:

    $("#id_salesPersonDistributor").change(function () {
         var url = $("#subsidiaryForm").attr("data-salesPersonsDistributorContact-url");  
         var salesPersonDistributorId = $(this).val(); 
         var id_sales = $(this).children(":selected").attr("id");
    
         if (id_sales == "new") {
           $("#id_salesPersonDistributor").modalForm({
               formURL: "{% url 'new_sales_person_distibutor' VCIUpdate %}"
          });
         } else {
         $.ajax({                      
           url: url,                    
           data: {
             'salesPersonDistributor': salesPersonDistributorId      
           },
           success: function (data) {   
             $("#salesPersonsDistributorContact").html(data); 
           }
         });
       }
    });
    
    view.py

    class NewSalesPersonDistributor(BSModalCreateView):
        template_name = 'newsalespersondistributor.html'
        form_class = NewSalesPersonDistributor
    
        def get_success_url(self):
              VCInumber = self.kwargs['pk']
              return reverse_lazy('VCIUpdate', kwargs={'pk': VCInumber})
    
    
    HTML

    
    {%csrf_令牌%}
    {{form.as_table}}
    ,
    
    模态形式的HTML

    <form method="post" action="">
       {% csrf_token %}
    
       <div class="modal-header">
        <h5 class="modal-title">Dodaj przedstawiciela</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
    
      <div class="modal-body">
       {% for field in form %}
         <div class="form-group{% if field.errors %} invalid{% endif %}">
           <label for="{{ field.id_for_label }}">{{ field.label }}</label>
           {{ field }}
           {% for error in field.errors %}
             <p class="help-block">{{ error }}</p>
           {% endfor %}
         </div>
       {% endfor %}
     </div>
    
    
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="submit-btn btn btn-primary">Create</button>
      </div>
    
    </form>
    
    
    
    {%csrf_令牌%}
    Dodaj przedstawiciela
    &时代;
    {%形式的字段为%}
    {{field.label}
    {{field}}
    {%字段中有错误。错误%}
    

    {{error}

    {%endfor%} {%endfor%} 接近 创造
    问题在于表单/输入的方法。 删除输入的提交类型,并将表单更改为:

    <form onsubmit="return null" />
    
    <input id="submit" value="save" />
    
    
    
    使用此选项可以避免重定向用户并向数据库输入信息?您好,在我的示例中,这不起作用。我甚至没有找到任何关于提交时返回null的信息。
    <form onsubmit="return null" />
    
    <input id="submit" value="save" />