0
我使用formValidation驗證Bootstrap
表單在我的ASP.NET
MVC
應用程序中。我已經使用這個插件,因爲它被稱爲bootstrapValidator
,從未遇到困難。現在我試圖馴服0.6.2版本,並且無法設置字段來驗證。FormValidation插件不驗證表單
我有以下腳本:
<script src="/Scripts/jquery-1.11.2.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.form.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/formValidation/formValidation.js"></script>
下面我把我的模式:
<div aria-hidden="true" aria-labelledby="modalBox_label" role="dialog" tabindex="-1" id="modalBox" class="modal fade"></div>
我有局部視圖,以填補我的模式與用戶的行動。我想最重要的部分是形式:
@using (Html.BeginForm("SomeAction", "SomeController", new { area = "SomeArea", divModal = divModal, divTarget = divTarget }, FormMethod.Post, new
{
id = modalForm,
@role = "form",
@class = "form",
@data_divTarget = "#" + divTarget
}))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.Id)
<div class="modal-body form-horizontal">
<div class="form-group">
@Html.LabelFor(m => m.Name, new { @class = "control-label col-sm-3" })
<div class="col-sm-5">
@Html.TextBoxFor(m => m.Name, new { @data_fv_notempty_message="You must enter name", @data_fv_notempty="True", @class="form-control", placeholder="Enter name" })
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" value="Submit form" class="btn btn-primary" />
</div>
}
當局部視圖被加載時,生成的代碼看起來是這樣的:
<div aria-hidden="false" aria-labelledby="modalBox_label" role="dialog" tabindex="-1" id="modalBox" class="modal fade in" style="display: block;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button data-dismiss="modal" class="close" type="button" id="modalBox_btnClose"><span aria-hidden="true">×</span><span class="sr-only">Закрыть</span></button>
<h4 id="modalBox_label" class="modal-title">Some title</h4>
</div>
<form role="form" method="post" id="modalBox_form" data-divtarget="#divTarget" class="form fv-form fv-form-bootstrap" action="/SomeController/SomeAction" novalidate="novalidate">
<button type="submit" class="fv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
<input type="hidden" value="someToken" name="__RequestVerificationToken">
<input type="hidden" value="0" name="Id" id="Id">
<div class="modal-body form-horizontal">
<div class="form-group">
<label for="Name" class="control-label col-sm-3">Name</label>
<div class="col-sm-5">
<input type="text" value="" placeholder="Enter name" name="Name" id="Name" data-fv-notempty-message="You must enter name" data-fv-notempty="True" class="form-control">
</div>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
<input type="submit" class="btn btn-primary" value="Submit form">
</div>
</form>
</div>
<div style="display: none; width: 0px; height: 0px;">
<script>
$(document).ready(function() {
validateModalForm('#modalBox_form');
});
</script>
</div>
</div>
</div>
哦,我下面的表格微小的腳本!它用來調用formValidation
插件和代碼是在這裏:
function validateModalForm(formId) {
$(formId).formValidation({
framework: 'bootstrap',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
}
}).on('success.form.fv', function (e) {
alert('Keep calm and do submit');
});
}
當我點擊提交按鈕,它會返回警告信息,然後提交。我無法檢測到問題。幫幫我! :(
它不應該工作按照當前的腳本只放一個bootstrap.js在頁面而不是多個。我在腳本部分看到了多個boostrap.js路徑 –
它們是兩個不同的腳本:第一個腳本(scripts/bootstrap.js)由'Bootstrap'提供,第二個腳本(scripts/formvalidation/framework/bootstrap。 js)由'FormValidation'提供。[Link](http://formvalidation.io/getting-started/#including-bootstrap-tab) – niebohr