刀片
{!! Form::open(array('method' => 'POST', 'id' => 'createUserForm')) !!}
{{ csrf_field() }}
{{ Form::hidden('SelectedRoleID') }}
<div class="form-group">
<label for="SelectRole">Select Role</label>
<div class="col-md-6">
<div id="tree1"></div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
{!! trans("Common.Button_Save") !!}
</button>
</div>
</div>
{!! Form::close() !!}
JQuery验证
$("form#" + createUserForm).validate({
ignore: "",
rules: {
SelectedRoleID: {
required: true,
number: true,
min: 1
}
},
messages: {
SelectedRoleID: {
required: "{!! trans('Role.RequiredRole') !!}"
}
},
submitHandler: function(form) {
debugger;
return;
}
});
错误消息显示为红色
问题
我可以在<div id="tree1"></div>
下显示JQuery Validate消息吗?实际上那是隐藏的领域
答案 0 :(得分:1)
$("form#" + createUserForm).validate({
ignore: "",
rules: {
SelectedRoleID: {
required: true,
number: true,
min: 1
}
},
messages: {
SelectedRoleID: {
required: "{!! trans('Role.RequiredRole') !!}"
}
},
errorPlacement: function (error, element) {
if(element[0].name === "SelectedRoleID") {
error.insertAfter($('#tree1'));
}
else {
$(error[0]).insertAfter($(element[0]));
}
},
submitHandler: function(form) {
debugger;
return;
}
});