@@ -26,14 +26,19 @@ Sys.Extended.UI.ValidatorCalloutBehavior = function Sys$Extended$UI$ValidatorCal
|
||||
this._isBuilt = false;
|
||||
this._focusHandler = Function.createDelegate(this, this._onfocus);
|
||||
this._closeClickHandler = Function.createDelegate(this, this._oncloseClick);
|
||||
this._originalValidationMethodOverriden = false;
|
||||
|
||||
Sys.Application.add_load(this._loadHandler);
|
||||
};
|
||||
|
||||
Sys.Extended.UI.ValidatorCalloutBehavior.prototype = {
|
||||
initialize: function() {
|
||||
Sys.Extended.UI.ValidatorCalloutBehavior.callBaseMethod(this, 'initialize');
|
||||
var elt = this.get_element();
|
||||
|
||||
// Override the evaluation method of the current validator
|
||||
if(elt.evaluationfunction) {
|
||||
this._originalValidationMethod = Function.createDelegate(elt, elt.evaluationfunction);
|
||||
this._validationMethodOverride = Function.createDelegate(this, this._onvalidate);
|
||||
elt.evaluationfunction = this._validationMethodOverride;
|
||||
}
|
||||
|
||||
// Check for failed server-side validation (indicated by non-empty ClientState)
|
||||
var clientState = this.get_ClientState();
|
||||
@@ -42,76 +47,16 @@ Sys.Extended.UI.ValidatorCalloutBehavior.prototype = {
|
||||
// Apply HightLightCssClass for failed server-side validation
|
||||
if(this._highlightCssClass)
|
||||
Sys.UI.DomElement.addCssClass(this._elementToValidate, this._highlightCssClass);
|
||||
|
||||
this.show();
|
||||
}
|
||||
},
|
||||
|
||||
_loadHandler: function(app, args) {
|
||||
var components = args.get_components();
|
||||
|
||||
for(var i = 0; i < components.length; i++) {
|
||||
var component = components[i];
|
||||
|
||||
if(component instanceof Sys.Extended.UI.ValidatorCalloutBehavior) {
|
||||
component.attachToValidator();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
attachToValidator: function() {
|
||||
var element = this.get_element();
|
||||
var self = this;
|
||||
|
||||
if(!this._originalValidationMethodOverriden) {
|
||||
if(window.jQuery) {
|
||||
window.jQuery(function($) {
|
||||
$(function() {
|
||||
self.checkPageValidators(element);
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
self.overrideEvaluationFunction(element);
|
||||
|
||||
this._originalValidationMethodOverriden = true;
|
||||
}
|
||||
},
|
||||
|
||||
checkPageValidators: function(element) {
|
||||
if(typeof (Page_Validators) === "undefined")
|
||||
return;
|
||||
|
||||
for(i = 0; i < Page_Validators.length; i++) {
|
||||
var validator = Page_Validators[i];
|
||||
|
||||
if(validator.ValidatorCalloutBehavior !== this)
|
||||
continue;
|
||||
|
||||
if(typeof (validator.evaluationfunction) === "function") {
|
||||
element.evaluationfunction = validator.evaluationfunction;
|
||||
this.overrideEvaluationFunction(element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
overrideEvaluationFunction: function(element) {
|
||||
// Override the evaluation method of the current validator
|
||||
if(element.evaluationfunction) {
|
||||
this._originalValidationMethod = Function.createDelegate(element, element.evaluationfunction);
|
||||
this._validationMethodOverride = Function.createDelegate(this, this._onvalidate);
|
||||
element.evaluationfunction = this._validationMethodOverride;
|
||||
element.removeAttribute("data-val-evaluationfunction");
|
||||
}
|
||||
},
|
||||
|
||||
_ensureCallout: function() {
|
||||
if(!this._isBuilt) {
|
||||
var elt = this.get_element();
|
||||
|
||||
// create the DOM elements
|
||||
var elementToValidate = this._elementToValidate = $get(elt.controltovalidate != null ? elt.controltovalidate : elt.getAttribute('data-val-controltovalidate'));
|
||||
var elementToValidate = this._elementToValidate = $get(elt.controltovalidate);
|
||||
var popupTableBody = document.createElement("tbody");
|
||||
var popupTableRow = document.createElement("tr");
|
||||
var calloutCell = document.createElement("td");
|
||||
@@ -269,7 +214,7 @@ Sys.Extended.UI.ValidatorCalloutBehavior.prototype = {
|
||||
{},
|
||||
null,
|
||||
this._popupTable);
|
||||
|
||||
|
||||
if(this._popupPosition == Sys.Extended.UI.ValidatorCalloutPosition.TopLeft)
|
||||
this._popupBehavior.set_positioningMode(Sys.Extended.UI.PositioningMode.TopLeft);
|
||||
else if(this._popupPosition == Sys.Extended.UI.ValidatorCalloutPosition.TopRight)
|
||||
@@ -332,8 +277,7 @@ Sys.Extended.UI.ValidatorCalloutBehavior.prototype = {
|
||||
},
|
||||
|
||||
_getErrorMessage: function() {
|
||||
var element = this.get_element();
|
||||
return element.errormessage || element.getAttribute('data-val-errormessage') || Sys.Extended.UI.Resources.ValidatorCallout_DefaultErrorMessage;
|
||||
return this.get_element().errormessage || Sys.Extended.UI.Resources.ValidatorCallout_DefaultErrorMessage;
|
||||
},
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user