I'm using laravel-jsValidation, http://ift.tt/1TqHo8s and my problem is that only the first rule in my list of rules is used.
In example below, the js will halt submit only if 'title' field is empty.
What am I doing wrong?
No errors whatsoever, backend or javascript.
Laravel v.5.1
/christian
Rules:
protected $rules = [
'title' => 'required|max:255',
'body' => 'required',
'company_id' => 'required|int',
'primary_site' => 'required|int',
'application_type' => 'required|int',
];
And in controller method:
$validator = \JsValidator::make($this->rules);
return view('form', array(
'person' => $person,
'validator' => $validator,
));
The javascript that is rendered in my view seems ok:
jQuery(document).ready(function(){
$("form").validate({
errorElement: 'span',
errorClass: 'help-block error-help-block',
errorPlacement: function(error, element) {
if (element.parent('.input-group').length ||
element.prop('type') === 'checkbox' || element.prop('type') === 'radio') {
error.insertAfter(element.parent());
// else just place the validation message immediatly after the input
} else {
error.insertAfter(element);
}
},
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error'); // add the Bootstrap error class to the control group
},
/*
// Uncomment this to mark as validated non required fields
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
},
*/
success: function(element) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success'); // remove the Boostrap error class from the control group
},
focusInvalid: false, // do not focus the last invalid input
invalidHandler: function(form, validator) {
if (!validator.numberOfInvalids())
return;
$('html, body').animate({
scrollTop: $(validator.errorList[0].element).offset().top
}, 1000);
$(validator.errorList[0].element).focus();
},
rules: {"title":{"laravelValidation":[["Required",[],"F\u00e4ltet title \u00e4r obligatoriskt.",true],["Max",["255"],"title f\u00e5r max inneh\u00e5lla 255 tecken.",false]]},"body":{"laravelValidation":[["Required",[],"F\u00e4ltet body \u00e4r obligatoriskt.",true]]},"company_id":{"laravelValidation":[["Required",[],"F\u00e4ltet company id \u00e4r obligatoriskt.",true],["Integer",[],"company id m\u00e5ste vara en siffra.",false]]},"primary_site":{"laravelValidation":[["Required",[],"F\u00e4ltet primary site \u00e4r obligatoriskt.",true],["Integer",[],"primary site m\u00e5ste vara en siffra.",false]]},"application_type":{"laravelValidation":[["Required",[],"F\u00e4ltet application type \u00e4r obligatoriskt.",true],["Integer",[],"application type m\u00e5ste vara en siffra.",false]]}} })
})
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire