Thursday, August 09, 2007

After of the plugin publication, I have had some request about how you alert the errors as "classic" YAV style or how you display all the errors inside a DIV.

In the first time, I question me, Why I want show all the errors inside a only layer?, focusing in accesibility it is better show the errors inside the label of the each field, but... Why not?. This is the idea:

I copy all the errors in the onError function, inside to a div, and remove the old.

	$(document).ready(function(){
$("#form1").yav({
onError: function(){
$("#errorContainer").append($(".error"));
$(".error").not($("#errorContainer .error")).remove();
$("#errorContainer").show();

return false;
}
});
$("#errorContainer a.close").click(function(){
$(".error").remove();
$("#errorContainer").hide();
})
});

Run the example.

The second idea. Really I have deprecated "classic" YAV style (a simple alert) because this is not usable and with a minimal accesibility. But if you want.... you can get the messages in the old jsErrors variable of YAV, but the syntax of this errors have changed a bit in the plugin. An error message is an map object like {id:"the_related_id_field", msg:"the error message"} or the string representation of this object. So:


$(document).ready(function(){
$("#form1").yav({
onError: function(){
var errorList = "Please check the next errors: \n\n";
for (var i=0; i errorList += ((typeof jsErrors[i]=="object")?jsErrors[i].msg:(eval("("+jsErrors[i]+")").msg)) + "\n";
}
alert(errorList);

return false;
}
});
});

Run the example.

If you have another idea, please say it to me.

Labels: , , ,

1 comments, Post a CommentPosted by posted by SeViR @ 9:32 PM
1 Comments
Jan 31, 2008 9:00:00 PM, Anonymous Anonymous said:
Hi, I like your idea1. How can I add styles to the field and label when there is error? And then have the error styles reset when user clicks on the field? Is that available?

Thanks.  
Links to this post
This design is under copyright of SeViR CW © 2007