我有这段代码:
$.fn.editable.defaults.mode = 'inline';
var editable = $('.x-editable').editable({
send: 'always',
validate: function() {
var form = editable.next().find('form');
if (!form.parsley().isValid()) {
return true;
}
}
});
editable.on('shown', function () {
var form = editable.next().find('form');
form.parsley();
});
和html:
<a class="x-editable toggle-content editable editable-pre-wrapped editable-click" href="#" data-toggle-limit="110" data-toggle-limit-padding="10" data-custom-params="{"inLaunchId":1489,"inActivitySummaryId":71962900}" data-disabled="false" data-emptytext="Add a comment" data-escape="true" data-name="inComment" data-placeholder="" data-tpl="<textarea maxLength="4000" data-parsley-pattern="^\d+$" data-popover="<p>Max length: <b>4000</b></p>"></textarea>" data-type="textarea" data-url="submitURL" data-value="text">text</a>
并且由于不知道原因ajax请求被发送两次,有谁知道为什么?如何解决这个问题?这是 jsFiddle
答案 0 :(得分:1)
由于您使用editable作为表单,而parsley仅用于验证 - 快速修复将禁用parsley提交表单。在这种情况下 - 字段将由bootstrap editable提交。
$.fn.editable.defaults.mode = 'inline';
var editable = $('.x-editable').editable({
send: 'always',
validate: function() {
var form = editable.next().find('form');
if (!form.parsley().isValid()) {
return true;
}
}
});
editable.on('shown', function () {
var form = editable.next().find('form');
form.parsley().on('form:submit', function() {
return false; // Don't submit form
});;
});