【发布时间】:2018-01-17 18:51:43
【问题描述】:
参考:Duplicate the Select/Option box when user clicks add more
我有一个带有下拉菜单的表单。当用户选择“添加更多字段”时,会出现下拉菜单的副本。但是,这会导致此错误。我想知道如何解决这个问题。
JSFiddle: https://jsfiddle.net/h3by56ws/
完整的错误:
{"error": "Shell form does not validate{'html_initial_name': u'initial-js_lib', 'form': <mooshell.forms.ShellForm object at 0x7f037e0df1d0>, 'html_name': 'js_lib', 'html_initial_id': u'initial-id_js_lib', 'label': u'Js lib', 'field': <django.forms.models.ModelChoiceField object at 0x7f037dec9b90>, 'help_text': '', 'name': 'js_lib'}{'html_initial_name': u'initial-js_wrap', 'form': <mooshell.forms.ShellForm object at 0x7f037e0df1d0>, 'html_name': 'js_wrap', 'html_initial_id': u'initial-id_js_wrap', 'label': u'Js wrap', 'field': <django.forms.fields.TypedChoiceField object at 0x7f037dec9f90>, 'help_text': '', 'name': 'js_wrap'}"}
HTML
<form method="POST" action="">
<!-- START OF EMPLOYEE -->
<div class="field third first">
<label for="employees">Employee</label>
<div id="select-employees" class="select-wrapper">
<select id="employees" name="employees">
<option value="">- Select Employee -</option>
<option value="1"> Bob </option>
<option value="1"> Mark </option>
<option value="1"> Alice </option>
<option value="1"> Jamie </option>
<option value="1"> Kris </option>
</select>
</div>
</div>
</br></br>
<button id="addMore" class="button small">Add Employee</button>
<!-- END OF EMPLOYEE -->
JS
$(function() {
$("#addMore").click(function(e) {
var newSelect = $("#employees").clone();
newSelect.val("");
$("#select-employees").append(newSelect);
});
});
【问题讨论】:
标签: javascript jquery html