Reputation: 1503
When the data are sent to the server to be save it is important to perform check up again even if the clientside validation is done but at that time if the model is not valid the response returned is in json format(from getErrors/ActiveForm::validate($model)) containing the messages and attributes that have errors.
When receiving how can I affect it to the form on the client side; each error from the reponse to it field on the form?
Is there any function on client side(js) that I can call passing the response to it?
Upvotes: 0
Views: 403
Reputation: 1481
Use
$.each(data, function(key, val) {
$("#"+key).after("<div class=\"help-block\">"+val+"</div>");
$("#"+key).closest(".form-group").addClass("has-error");
});
This will append error to corresponding field.
Upvotes: 1