我不知道这是怎么回事,我已经按照流星欧芹包的步骤进行了操作。
如果没有有效输入,我希望表单不是get submit。虽然它为url添加时显示未定义,但我想限制表单从提交到满足条件。
<form class="form-horizontal" role="form" id="addItem" data-parsley-validate> <div class="form-group form-group-sm"> <label class="col-sm-2 control-label" for="sm">Listing URL</label> <div class="col-sm-3"> <input type="url" class="form-control" id="listing_url" placeholder="Enter the listing URL" data-required='true' data-type='url' data-trigger='change'/> </div> </div> <div class="container "> <div class="panel-footer"> <button class="btn btn-danger btn-md">Clear</button> <button class="btn btn-success btn-md pull-right submit">Submit</button> </div> </div>
Template.addItem.events({
'click .submit': function() {
var current_date = moment().format("DD-MM-YYYY hh:mm");
var insertform = {
created_at: current_date,
url: $('#url').val()
}
console.log('insertform:', insertform);
insertForm.insert(insertform);
}
})
Template.addItem.onRendered = (function () {
// Setup parsley form validation
// replace form with the id of your form
$('#addItem').parsley({trigger: 'change'});
});
答案 0 :(得分:0)
您需要检查表单是否有效,然后运行您的提交代码。
var formValid = $('#addItem').parsley('validate')
if (formValid)
{
var current_date = moment().format("DD-MM-YYYY hh:mm");
var insertform = {
created_at: current_date,
url: $('#url').val()
}
console.log('insertform:', insertform);
insertForm.insert(insertform);
}