Bu yüzden bu jqueryui widget'ını oluşturdum. Hataları akışa alabileceğim bir div oluşturur. Widget kodu şuna benzer:
$.widget('ui.miniErrorLog', {
logStart: "<ul>", // these next 4 elements are actually a bunch more complicated.
logEnd: "</ul>",
errStart: "<li>",
errEnd: "</li>",
content: "",
refs: [],
_create: function() { $(this.element).addClass( "ui-state-error" ).hide(); },
clear: function() {
this.content = "";
for ( var i in this.refs )
$( this.refs[i] ).removeClass( "ui-state-error" );
this.refs = [];
$(this.element).empty().hide();
},
addError: function( msg, ref ) {
this.content += this.errStart + msg + this.errEnd;
if ( ref ) {
if ( ref instanceof Array )
this.refs.concat( ref );
else
this.refs.push( ref );
for ( var i in this.refs )
$( this.refs[i] ).addClass( "ui-state-error" );
}
$(this.element).html( this.logStart + this.content + this.logEnd ).show();
},
hasError: function()
{
if ( this.refs.length )
return true;
return false;
},
});
Buna hata mesajları ve hata durumuna getirilecek sayfa öğelerine referanslar ekleyebilirim. Bunu diyalogları doğrulamak için kullanıyorum. "AddError" yönteminde, tek bir kimliği veya bir dizi kimliği iletebilirim, örneğin:
$( "#registerDialogError" ).miniErrorLog(
'addError',
"Your passwords don't match.",
[ "#registerDialogPassword1", "#registerDialogPassword2" ] );
Ama bir id dizisini verdiğimde işe yaramıyor. Sorun şu satırlarda (sanırım):
if ( ref instanceof Array )
this.refs.concat( ref );
else
this.refs.push( ref );
Bu concat neden çalışmıyor? this.refs ve ref dizilerdir. Peki neden concat çalışmıyor?
Bonus: Bu widget'ta başka aptalca bir şey yapıyor muyum? Bu benim ilkim.