summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts
diff options
context:
space:
mode:
authorxue <>2006-04-25 01:27:04 +0000
committerxue <>2006-04-25 01:27:04 +0000
commit1afc913c386bba8e6072c278b0eb4fd9818ab310 (patch)
tree40cc63eb41f47e0ac392c692619640dca57cd262 /framework/Web/Javascripts
parentfd019bf034ef4dbedfc305c77fed0dbd83a732c4 (diff)
Undo previous checkin (which goes int 3.0 branch and will be merged back).
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r--framework/Web/Javascripts/colorpicker/colorpicker.js59
-rw-r--r--framework/Web/Javascripts/datepicker/datepicker.js96
-rw-r--r--framework/Web/Javascripts/extended/event.js5
-rw-r--r--framework/Web/Javascripts/js/colorpicker.js36
-rw-r--r--framework/Web/Javascripts/js/datepicker.js86
-rw-r--r--framework/Web/Javascripts/js/prado.js5
-rw-r--r--framework/Web/Javascripts/js/validator.js237
-rw-r--r--framework/Web/Javascripts/prado/form.js2
-rw-r--r--framework/Web/Javascripts/prado/validation3.js396
9 files changed, 206 insertions, 716 deletions
diff --git a/framework/Web/Javascripts/colorpicker/colorpicker.js b/framework/Web/Javascripts/colorpicker/colorpicker.js
index dc80f0c7..cc4587ff 100644
--- a/framework/Web/Javascripts/colorpicker/colorpicker.js
+++ b/framework/Web/Javascripts/colorpicker/colorpicker.js
@@ -83,7 +83,7 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
if(mode == "Full")
this.initializeFullPicker();
}
- this.show(mode);
+ this.show();
},
show : function(type)
@@ -108,7 +108,6 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
if(type == "Full")
{
- this.observeMouseMovement();
var color = Rico.Color.createFromHex(this.input.value);
this.inputs.oldColor.style.backgroundColor = color.asHex();
this.setColor(color,true);
@@ -125,14 +124,8 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
this.element.style.display = "none";
this.showing = false;
- Event.stopObserving(document.body, "click", this._documentClickEvent);
+ Event.stopObserving(document.body, "click", this._documentClickEvent);
Event.stopObserving(document,"keydown", this._documentKeyDownEvent);
-
- if(this._observingMouseMove)
- {
- Event.stopObserving(document.body, "mousemove", this._onMouseMove);
- this._observingMouseMove = false;
- }
}
},
@@ -215,7 +208,7 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
{
this.input.value = color.toString().toUpperCase();
this.button.style.backgroundColor = color.toString();
- if(typeof(this.onChange) == "function")
+ if(isFunction(this.onChange))
this.onChange(color);
},
@@ -253,7 +246,7 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
TR(null,
TD(null,'H:'),
- TD(null,this.inputs['H'], '??')),
+ TD(null,this.inputs['H'], '°')),
TR(null,
TD(null,'S:'),
@@ -340,46 +333,34 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
this._onMouseMove = this.onMouseMove.bind(this);
Event.observe(this.inputs.background, "mousedown", this._onColorMouseDown);
- Event.observe(this.inputs.selector, "mousedown", this._onColorMouseDown);
Event.observe(this.inputs.hue, "mousedown", this._onHueMouseDown);
- Event.observe(this.inputs.slider, "mousedown", this._onHueMouseDown);
Event.observe(document.body, "mouseup", this._onMouseUp);
-
- this.observeMouseMovement();
+
+ //Because of using the CSS filter, IE can't do colour change quickly
+ //if(!Prado.Browser().ie)
+ Event.observe(document.body, "mousemove", this._onMouseMove);
Event.observe(this.buttons.Cancel, "click", this.hide.bindEvent(this,this.options['Mode']));
Event.observe(this.buttons.OK, "click", this.onOKClicked.bind(this));
},
- observeMouseMovement : function()
- {
- if(!this._observingMouseMove)
- {
- Event.observe(document.body, "mousemove", this._onMouseMove);
- this._observingMouseMove = true;
- }
- },
-
onColorMouseDown : function(ev)
{
this.isMouseDownOnColor = true;
this.onMouseMove(ev);
- Event.stop(ev);
},
onHueMouseDown : function(ev)
{
this.isMouseDownOnHue = true;
this.onMouseMove(ev);
- Event.stop(ev);
},
onMouseUp : function(ev)
{
this.isMouseDownOnColor = false;
this.isMouseDownOnHue = false;
- Event.stop(ev);
},
onMouseMove : function(ev)
@@ -388,7 +369,6 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
this.changeSV(ev);
if(this.isMouseDownOnHue)
this.changeH(ev);
- Event.stop(ev);
},
changeSV : function(ev)
@@ -396,25 +376,18 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
var px = Event.pointerX(ev);
var py = Event.pointerY(ev);
var pos = Position.cumulativeOffset(this.inputs.background);
-
var x = this.truncate(px - pos[0],0,255);
var y = this.truncate(py - pos[1],0,255);
+ var h = this.truncate(this.inputs.H.value,0,360)/360;
var s = x/255;
var b = (255-y)/255;
- var current_s = parseInt(this.inputs.S.value);
- var current_b = parseInt(this.inputs.V.value);
-
- if(current_s == parseInt(s*100) && current_b == parseInt(b*100)) return;
-
- var h = this.truncate(this.inputs.H.value,0,360)/360;
var color = new Rico.Color();
color.rgb = Rico.Color.HSBtoRGB(h,s,b);
-
this.inputs.selector.style.left = x+"px";
this.inputs.selector.style.top = y+"px";
@@ -430,10 +403,6 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
var y = this.truncate(py - pos[1],0,255);
var h = (255-y)/255;
- var current_h = this.truncate(this.inputs.H.value,0,360);
- current_h = current_h == 0 ? 360 : current_h;
- if(current_h == parseInt(h*360)) return;
-
var s = parseInt(this.inputs.S.value)/100;
var b = parseInt(this.inputs.V.value)/100;
var color = new Rico.Color();
@@ -503,8 +472,14 @@ Object.extend(Prado.WebUI.TColorPicker.prototype,
var images = Prado.WebUI.TColorPicker.UIImages;
var changeCss = color.isBright() ? 'removeClassName' : 'addClassName';
- Element[changeCss](this.inputs.selector, 'target_white');
-
+ Element[changeCss](this.inputs.selector, 'target_white');
+/* if(color.isBright())
+ Element.removeCssClass(this.inputs.selector, 'target_white');
+ //this.inputs.selector.src = images['target_black.gif'];
+ else
+ Element.addCssClass(this.inputs.selector, 'target_white');
+ //this.inputs.selector.src = images['target_white.gif'];
+*/
if(update)
this.updateSelectors(color);
},
diff --git a/framework/Web/Javascripts/datepicker/datepicker.js b/framework/Web/Javascripts/datepicker/datepicker.js
index 79763811..e906120c 100644
--- a/framework/Web/Javascripts/datepicker/datepicker.js
+++ b/framework/Web/Javascripts/datepicker/datepicker.js
@@ -1,51 +1,10 @@
Prado.WebUI.TDatePicker = Class.create();
-Object.extend(Prado.WebUI.TDatePicker,
-{
- /**
- * @return Date the date from drop down list options.
- */
- getDropDownDate : function(control)
- {
- var now=new Date();
- var year=now.getFullYear();
- var month=now.getMonth();
- var day=1;
-
- var month_list = this.getMonthListControl(control);
- var day_list = this.getDayListControl(control);
- var year_list = this.getYearListControl(control);
-
- var day = day_list ? $F(day_list) : 1;
- var month = month_list ? $F(month_list) : now.getMonth();
- var year = year_list ? $F(year_list) : now.getFullYear();
-
- return new Date(year,month,day, 0, 0, 0);
- },
-
- getYearListControl : function(control)
- {
- return $(control.id+"_year");
- },
-
- getMonthListControl : function(control)
- {
- return $(control.id+"_month");
- },
-
- getDayListControl : function(control)
- {
- return $(control.id+"_day");
- }
-});
-
Prado.WebUI.TDatePicker.prototype =
{
MonthNames : [ "January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
],
- AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May",
- "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
@@ -229,7 +188,7 @@ Prado.WebUI.TDatePicker.prototype =
var todayButton = document.createElement("button");
todayButton.className = "todayButton";
var today = this.newDate();
- var buttonText = today.SimpleFormat(this.Format,this);
+ var buttonText = today.SimpleFormat(this.Format);
todayButton.appendChild(document.createTextNode(buttonText));
div.appendChild(todayButton);
@@ -427,27 +386,20 @@ Prado.WebUI.TDatePicker.prototype =
return false;
},
- onChange : function()
+ onchange : function()
{
if(this.options.InputMode == "TextBox")
- {
this.control.value = this.formatDate();
- Event.fireEvent(this.control, "change");
- }
else
{
- var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
- var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+ var day = $(this.options.ID+"_day");
+ var month = $(this.options.ID+"_month");
+ var year = $(this.options.ID+"_year");
var date = this.selectedDate;
if(day)
- {
day.selectedIndex = date.getDate()-1;
- }
if(month)
- {
month.selectedIndex = date.getMonth();
- }
if(year)
{
var years = year.options;
@@ -455,20 +407,19 @@ Prado.WebUI.TDatePicker.prototype =
for(var i = 0; i < years.length; i++)
years[i].selected = years[i].value.toInteger() == currentYear;
}
- Event.fireEvent(day || month || year, "change");
}
},
formatDate : function()
{
- return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : '';
+ return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format) : '';
},
newDate : function(date)
{
if(!date)
date = new Date();
- if(typeof(date) == "string" || typeof(date) == "number")
+ if(isString(date) || isNumber(date))
date = new Date(date);
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0,0,0);
},
@@ -481,8 +432,8 @@ Prado.WebUI.TDatePicker.prototype =
this.updateHeader();
this.update();
- if (typeof(this.onChange) == "function")
- this.onChange();
+ if (isFunction(this.onchange))
+ this.onchange();
},
getElement : function()
@@ -492,7 +443,7 @@ Prado.WebUI.TDatePicker.prototype =
getSelectedDate : function ()
{
- return this.selectedDate == null ? null : this.newDate(this.selectedDate);
+ return isNull(this.selectedDate) ? null : this.newDate(this.selectedDate);
},
setYear : function(year)
@@ -529,9 +480,8 @@ Prado.WebUI.TDatePicker.prototype =
pos[1] += this.control.offsetHeight;
else
{
- var dayList = Prado.WebUI.TDatePicker.getDayListControl(this.control);
- if(dayList)
- pos[1] += dayList.offsetHeight-1;
+ if($(this.options.ID+"_day"))
+ pos[1] += $(this.options.ID+"_day").offsetHeight-1;
}
this._calDiv.style.display = "block";
@@ -543,7 +493,7 @@ Prado.WebUI.TDatePicker.prototype =
this.documentKeyDownEvent = this.keyPressed.bindEvent(this);
Event.observe(document.body, "click", this.documentClickEvent);
var date = this.getDateFromInput();
- if(date)
+ if(!isNull(date))
{
this.selectedDate = date;
this.setSelectedDate(date);
@@ -558,7 +508,20 @@ Prado.WebUI.TDatePicker.prototype =
if(this.options.InputMode == "TextBox")
return Date.SimpleParse($F(this.control), this.Format);
else
- return Prado.WebUI.TDatePicker.getDropDownDate(this.control);
+ {
+ var now=new Date();
+ var year=now.getFullYear();
+ var month=now.getMonth();
+ var date=1;
+ if($(this.options.ID+"_day"))
+ day = $F(this.options.ID+"_day");
+ if($(this.options.ID+"_month"))
+ month = $F(this.options.ID+"_month");
+ if($(this.options.ID+"_year"))
+ year = $F(this.options.ID+"_year");
+ var newdate=new Date(year,month,day, 0, 0, 0);
+ return newdate;
+ }
},
//hide the calendar when clicked outside any calendar
@@ -647,10 +610,7 @@ Prado.WebUI.TDatePicker.prototype =
hover : function(ev)
{
//conditionally add the hover class to the event target element.
- if(ev.type == "mouseover")
- Event.element(ev).addClassName("hover");
- else
- Event.element(ev).removeClassName("hover");
+ Element.condClassName(Event.element(ev), "hover", ev.type=="mouseover");
},
updateHeader : function () {
diff --git a/framework/Web/Javascripts/extended/event.js b/framework/Web/Javascripts/extended/event.js
index 13e875da..40cf60a1 100644
--- a/framework/Web/Javascripts/extended/event.js
+++ b/framework/Web/Javascripts/extended/event.js
@@ -95,10 +95,9 @@ Object.extend(Event,
else if(element.fireEvent)
{
element.fireEvent('on'+type);
- if(element[type])
- element[type]();
+ element[type]();
}
- else if(element[type])
+ else
element[type]();
}
}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/js/colorpicker.js b/framework/Web/Javascripts/js/colorpicker.js
index b926dc93..27e180b0 100644
--- a/framework/Web/Javascripts/js/colorpicker.js
+++ b/framework/Web/Javascripts/js/colorpicker.js
@@ -257,7 +257,7 @@ this.input.parentNode.appendChild(this.iePopUp);
if(mode == "Full")
this.initializeFullPicker();
}
-this.show(mode);
+this.show();
},
show : function(type)
{
@@ -276,7 +276,6 @@ Event.observe(document,"keydown", this._documentKeyDownEvent);
this.showing = true;
if(type == "Full")
{
-this.observeMouseMovement();
var color = Rico.Color.createFromHex(this.input.value);
this.inputs.oldColor.style.backgroundColor = color.asHex();
this.setColor(color,true);
@@ -293,11 +292,6 @@ this.element.style.display = "none";
this.showing = false;
Event.stopObserving(document.body, "click", this._documentClickEvent);
Event.stopObserving(document,"keydown", this._documentKeyDownEvent);
-if(this._observingMouseMove)
-{
-Event.stopObserving(document.body, "mousemove", this._onMouseMove);
-this._observingMouseMove = false;
-}
}
},
keyPressed : function(event,type)
@@ -373,7 +367,7 @@ updateColor : function(color)
{
this.input.value = color.toString().toUpperCase();
this.button.style.backgroundColor = color.toString();
-if(typeof(this.onChange) == "function")
+if(isFunction(this.onChange))
this.onChange(color);
},
getFullPickerContainer : function(pickerID)
@@ -400,7 +394,7 @@ TD({className:'currentcolor',colSpan:2},
this.inputs['currentColor'], this.inputs['oldColor'])),
TR(null,
TD(null,'H:'),
-TD(null,this.inputs['H'], '??')),
+TD(null,this.inputs['H'], '°')),
TR(null,
TD(null,'S:'),
TD(null,this.inputs['S'], '%')),
@@ -469,39 +463,26 @@ this._onHueMouseDown = this.onHueMouseDown.bind(this);
this._onMouseUp = this.onMouseUp.bind(this);
this._onMouseMove = this.onMouseMove.bind(this);
Event.observe(this.inputs.background, "mousedown", this._onColorMouseDown);
-Event.observe(this.inputs.selector, "mousedown", this._onColorMouseDown);
Event.observe(this.inputs.hue, "mousedown", this._onHueMouseDown);
-Event.observe(this.inputs.slider, "mousedown", this._onHueMouseDown);
Event.observe(document.body, "mouseup", this._onMouseUp);
-this.observeMouseMovement();
+Event.observe(document.body, "mousemove", this._onMouseMove);
Event.observe(this.buttons.Cancel, "click", this.hide.bindEvent(this,this.options['Mode']));
Event.observe(this.buttons.OK, "click", this.onOKClicked.bind(this));
},
-observeMouseMovement : function()
-{
-if(!this._observingMouseMove)
-{
-Event.observe(document.body, "mousemove", this._onMouseMove);
-this._observingMouseMove = true;
-}
-},
onColorMouseDown : function(ev)
{
this.isMouseDownOnColor = true;
this.onMouseMove(ev);
-Event.stop(ev);
},
onHueMouseDown : function(ev)
{
this.isMouseDownOnHue = true;
this.onMouseMove(ev);
-Event.stop(ev);
},
onMouseUp : function(ev)
{
this.isMouseDownOnColor = false;
this.isMouseDownOnHue = false;
-Event.stop(ev);
},
onMouseMove : function(ev)
{
@@ -509,7 +490,6 @@ if(this.isMouseDownOnColor)
this.changeSV(ev);
if(this.isMouseDownOnHue)
this.changeH(ev);
-Event.stop(ev);
},
changeSV : function(ev)
{
@@ -518,12 +498,9 @@ var py = Event.pointerY(ev);
var pos = Position.cumulativeOffset(this.inputs.background);
var x = this.truncate(px - pos[0],0,255);
var y = this.truncate(py - pos[1],0,255);
+var h = this.truncate(this.inputs.H.value,0,360)/360;
var s = x/255;
var b = (255-y)/255;
-var current_s = parseInt(this.inputs.S.value);
-var current_b = parseInt(this.inputs.V.value);
-if(current_s == parseInt(s*100) && current_b == parseInt(b*100)) return;
-var h = this.truncate(this.inputs.H.value,0,360)/360;
var color = new Rico.Color();
color.rgb = Rico.Color.HSBtoRGB(h,s,b);
this.inputs.selector.style.left = x+"px";
@@ -537,9 +514,6 @@ var py = Event.pointerY(ev);
var pos = Position.cumulativeOffset(this.inputs.background);
var y = this.truncate(py - pos[1],0,255);
var h = (255-y)/255;
-var current_h = this.truncate(this.inputs.H.value,0,360);
-current_h = current_h == 0 ? 360 : current_h;
-if(current_h == parseInt(h*360)) return;
var s = parseInt(this.inputs.S.value)/100;
var b = parseInt(this.inputs.V.value)/100;
var color = new Rico.Color();
diff --git a/framework/Web/Javascripts/js/datepicker.js b/framework/Web/Javascripts/js/datepicker.js
index 19d39bbe..e82507ea 100644
--- a/framework/Web/Javascripts/js/datepicker.js
+++ b/framework/Web/Javascripts/js/datepicker.js
@@ -1,41 +1,10 @@
Prado.WebUI.TDatePicker = Class.create();
-Object.extend(Prado.WebUI.TDatePicker,
-{
-getDropDownDate : function(control)
-{
-var now=new Date();
-var year=now.getFullYear();
-var month=now.getMonth();
-var day=1;
-var month_list = this.getMonthListControl(control);
- var day_list = this.getDayListControl(control);
- var year_list = this.getYearListControl(control);
-var day = day_list ? $F(day_list) : 1;
-var month = month_list ? $F(month_list) : now.getMonth();
-var year = year_list ? $F(year_list) : now.getFullYear();
-return new Date(year,month,day, 0, 0, 0);
-},
-getYearListControl : function(control)
-{
-return $(control.id+"_year");
-},
-getMonthListControl : function(control)
-{
-return $(control.id+"_month");
-},
-getDayListControl : function(control)
-{
-return $(control.id+"_day");
-}
-});
Prado.WebUI.TDatePicker.prototype =
{
MonthNames : ["January","February","March","April",
"May","June","July","August",
"September","October","November","December"
],
-AbbreviatedMonthNames : ["Jan", "Feb", "Mar", "Apr", "May",
-"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
Format : "yyyy-MM-dd",
FirstDayOfWeek : 1,
@@ -169,7 +138,7 @@ this._calDiv.appendChild(div);
var todayButton = document.createElement("button");
todayButton.className = "todayButton";
var today = this.newDate();
-var buttonText = today.SimpleFormat(this.Format,this);
+var buttonText = today.SimpleFormat(this.Format);
todayButton.appendChild(document.createTextNode(buttonText));
div.appendChild(todayButton);
if(Prado.Browser().ie)
@@ -323,27 +292,20 @@ var m = d.getMonth() + n;
this.setMonth(m);
return false;
},
-onChange : function()
+onchange : function()
{
if(this.options.InputMode == "TextBox")
-{
this.control.value = this.formatDate();
-Event.fireEvent(this.control, "change");
-}
else
{
-var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
-var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
-var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
+var day = $(this.options.ID+"_day");
+var month = $(this.options.ID+"_month");
+var year = $(this.options.ID+"_year");
var date = this.selectedDate;
if(day)
-{
day.selectedIndex = date.getDate()-1;
-}
if(month)
-{
month.selectedIndex = date.getMonth();
-}
if(year)
{
var years = year.options;
@@ -351,18 +313,17 @@ var currentYear = date.getFullYear();
for(var i = 0; i < years.length; i++)
years[i].selected = years[i].value.toInteger() == currentYear;
}
-Event.fireEvent(day || month || year, "change");
}
},
formatDate : function()
{
-return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format,this) : '';
+return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format) : '';
},
newDate : function(date)
{
if(!date)
date = new Date();
-if(typeof(date) == "string" || typeof(date) == "number")
+if(isString(date)|| isNumber(date))
date = new Date(date);
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0,0,0);
},
@@ -373,8 +334,8 @@ return;
this.selectedDate = this.newDate(date);
this.updateHeader();
this.update();
-if (typeof(this.onChange) == "function")
-this.onChange();
+if (isFunction(this.onchange))
+this.onchange();
},
getElement : function()
{
@@ -382,7 +343,7 @@ return this._calDiv;
},
getSelectedDate : function ()
{
-return this.selectedDate == null ? null : this.newDate(this.selectedDate);
+return isNull(this.selectedDate) ? null : this.newDate(this.selectedDate);
},
setYear : function(year)
{
@@ -413,9 +374,8 @@ if(this.options.InputMode == "TextBox")
pos[1] += this.control.offsetHeight;
else
{
-var dayList = Prado.WebUI.TDatePicker.getDayListControl(this.control);
-if(dayList)
-pos[1] += dayList.offsetHeight-1;
+if($(this.options.ID+"_day"))
+pos[1] += $(this.options.ID+"_day").offsetHeight-1;
}
this._calDiv.style.display = "block";
this._calDiv.style.top = (pos[1]-1) + "px";
@@ -425,7 +385,7 @@ this.documentClickEvent = this.hideOnClick.bindEvent(this);
this.documentKeyDownEvent = this.keyPressed.bindEvent(this);
Event.observe(document.body, "click", this.documentClickEvent);
var date = this.getDateFromInput();
-if(date)
+if(!isNull(date))
{
this.selectedDate = date;
this.setSelectedDate(date);
@@ -439,7 +399,20 @@ getDateFromInput : function()
if(this.options.InputMode == "TextBox")
return Date.SimpleParse($F(this.control), this.Format);
else
-return Prado.WebUI.TDatePicker.getDropDownDate(this.control);
+{
+var now=new Date();
+var year=now.getFullYear();
+var month=now.getMonth();
+var date=1;
+if($(this.options.ID+"_day"))
+day = $F(this.options.ID+"_day");
+if($(this.options.ID+"_month"))
+month = $F(this.options.ID+"_month");
+if($(this.options.ID+"_year"))
+year = $F(this.options.ID+"_year");
+var newdate=new Date(year,month,day, 0, 0, 0);
+return newdate;
+}
},
hideOnClick : function(ev)
{
@@ -511,10 +484,7 @@ this.dateSlot[index].data.parentNode.className = "empty";
},
hover : function(ev)
{
-if(ev.type == "mouseover")
-Event.element(ev).addClassName("hover");
-else
-Event.element(ev).removeClassName("hover");
+Element.condClassName(Event.element(ev), "hover", ev.type=="mouseover");
},
updateHeader : function () {
var options = this._monthSelect.options;
diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js
index c7145188..6737d4ce 100644
--- a/framework/Web/Javascripts/js/prado.js
+++ b/framework/Web/Javascripts/js/prado.js
@@ -1299,10 +1299,9 @@ element.dispatchEvent(event);
else if(element.fireEvent)
{
element.fireEvent('on'+type);
-if(element[type])
element[type]();
}
-else if(element[type])
+else
element[type]();
}
});
@@ -1869,9 +1868,9 @@ lastFocus.value = options['EventTarget'];
}
$('PRADO_POSTBACK_TARGET').value = options['EventTarget'];
$('PRADO_POSTBACK_PARAMETER').value = options['EventParameter'];
+Event.fireEvent(form,"submit");
if(options['StopEvent'])
Event.stop(event);
-Event.fireEvent(form,"submit");
}
Prado.Element =
{
diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js
index 38d8a2a4..7d343d87 100644
--- a/framework/Web/Javascripts/js/validator.js
+++ b/framework/Web/Javascripts/js/validator.js
@@ -26,7 +26,6 @@ if(this.managers[formID])
this.managers[formID].addValidator(validator);
else
throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
-return this.managers[formID];
},
addSummary : function(formID, validator)
{
@@ -34,11 +33,9 @@ if(this.managers[formID])
this.managers[formID].addSummary(validator);
else
throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
-return this.managers[formID];
}
});
-Prado.ValidationManager = Class.create();
-Prado.ValidationManager.prototype =
+Prado.Validation.prototype =
{
validators : [],
summaries : [],
@@ -59,12 +56,13 @@ return this._validateNonGroup();
_validateGroup: function(groupID)
{
var valid = true;
+var manager = this;
if(this.groups.include(groupID))
{
this.validators.each(function(validator)
{
if(validator.group == groupID)
-valid = valid & validator.validate();
+valid = valid & validator.validate(manager);
else
validator.hide();
});
@@ -75,10 +73,11 @@ return valid;
_validateNonGroup : function()
{
var valid = true;
+var manager = this;
this.validators.each(function(validator)
{
if(!validator.group)
-valid = valid & validator.validate();
+valid = valid & validator.validate(manager);
else
validator.hide();
});
@@ -272,9 +271,8 @@ enabled : true,
visible : false,
isValid : true,
options : {},
-_isObserving : {},
+_isObserving : false,
group : null,
-manager : null,
initialize : function(options)
{
options.OnValidate = options.OnValidate || Prototype.emptyFunction;
@@ -284,7 +282,7 @@ this.options = options;
this.control = $(options.ControlToValidate);
this.message = $(options.ID);
this.group = options.ValidationGroup;
-this.manager = Prado.Validation.addValidator(options.FormID, this);
+Prado.Validation.addValidator(options.FormID, this);
},
getErrorMessage : function()
{
@@ -298,7 +296,6 @@ if(this.options.Display == "Dynamic")
this.isValid ? this.message.hide() : this.message.show();
this.message.style.visibility = this.isValid ? "hidden" : "visible";
}
-if(this.control)
this.updateControlCssClass(this.control, this.isValid);
if(this.options.FocusOnError && !this.isValid)
Prado.Element.focus(this.options.FocusElementID);
@@ -321,36 +318,33 @@ this.isValid = true;
this.updateControl();
this.visible = false;
},
-validate : function()
+validate : function(manager)
{
if(this.enabled)
-this.isValid = this.evaluateIsValid();
-this.options.OnValidate(this);
+this.isValid = this.evaluateIsValid(manager);
+this.options.OnValidate(this, manager);
this.updateControl();
if(this.isValid)
-this.options.OnSuccess(this);
+this.options.OnSuccess(this, manager);
else
-this.options.OnError(this);
-this.observeChanges(this.control);
+this.options.OnError(this, manager);
+this.observeChanges(manager);
return this.isValid;
},
-observeChanges : function(control)
+observeChanges : function(manager)
{
-if(!control) return;
-var canObserveChanges = this.options.ObserveChanges != false;
-var currentlyObserving = this._isObserving[control.id+this.options.ID];
-if(canObserveChanges && !currentlyObserving)
+if(this.options.ObserveChanges != false && !this._isObserving)
{
var validator = this;
-Event.observe(control, 'change', function()
+Event.observe(this.control, 'change', function()
{
if(validator.visible)
{
-validator.validate();
-validator.manager.updateSummary(validator.group);
+validator.validate(manager);
+manager.updateSummary(validator.group);
}
});
-this._isObserving[control.id+this.options.ID] = true;
+this._isObserving = true;
}
},
trim : function(value)
@@ -360,7 +354,7 @@ return typeof(value) == "string" ? value.trim() : "";
convert : function(dataType, value)
{
if(typeof(value) == "undefined")
-value = this.getValidationValue();
+value = $F(this.control);
var string = new String(value);
switch(dataType)
{
@@ -369,116 +363,18 @@ return string.toInteger();
case "Double" :
case "Float" :
return string.toDouble(this.options.DecimalChar);
+case "Currency" :
+return string.toCurrency(this.options.GroupChar, this.options.Digits, this.options.DecimalChar);
case "Date":
-if(typeof(value) != "string")
-return value;
-else
-{
var value = string.toDate(this.options.DateFormat);
if(value && typeof(value.getTime) == "function")
return value.getTime();
else
return null;
-}
case "String":
return string.toString();
}
return value;
-},
-getValidationValue : function(control)
- {
- if(!control)
- control = this.control
- switch(this.options.ControlType)
- {
- case 'TDatePicker':
- if(control.type == "text")
- return this.trim($F(control));
- else
- {
- this.observeDatePickerChanges();
-return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();
- }
- default:
- if(this.isListControlType())
- return this.getFirstSelectedListValue();
- else
- return this.trim($F(control));
- }
- },
-observeDatePickerChanges : function()
- {
- if(Prado.Browser().ie)
- {
- var DatePicker = Prado.WebUI.TDatePicker;
- this.observeChanges(DatePicker.getDayListControl(this.control));
-this.observeChanges(DatePicker.getMonthListControl(this.control));
-this.observeChanges(DatePicker.getYearListControl(this.control));
- }
- },
-getSelectedValuesAndChecks : function(elements, initialValue)
-{
-var checked = 0;
-var values = [];
-var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
-elements.each(function(element)
-{
-if(element[isSelected] && element.value != initialValue)
-{
-checked++;
-values.push(element.value);
-}
-});
-return {'checks' : checked, 'values' : values};
-},
-getListElements : function()
-{
-switch(this.options.ControlType)
-{
-case 'TCheckBoxList': case 'TRadioButtonList':
-var elements = [];
-for(var i = 0; i < this.options.TotalItems; i++)
-{
-var element = $(this.options.ControlToValidate+"_"+i);
-if(this.isCheckBoxType(element))
-elements.push(element);
-}
-return elements;
-case 'TListBox':
-var elements = [];
-var element = $(this.options.ControlToValidate);
-if(element && (type = element.type.toLowerCase()))
-{
-if(type == "select-one" || type == "select-multiple")
-elements = $A(element.options);
-}
-return elements;
-default:
-return [];
-}
-},
-isCheckBoxType : function(element)
-{
-if(element && element.type)
-{
-var type = element.type.toLowerCase();
-return type == "checkbox" || type == "radio";
-}
-return false;
-},
-isListControlType : function()
-{
-var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
-return list.include(this.options.ControlType);
-},
-getFirstSelectedListValue : function()
-{
-var initial = "";
-if(typeof(this.options.InitialValue) != "undefined")
-initial = this.options.InitialValue;
-var elements = this.getListElements();
-var selection = this.getSelectedValuesAndChecks(elements, initial);
-return selection.values.length > 0 ? selection.values[0] : initial;
}
}
Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator,
@@ -492,7 +388,7 @@ return true;
}
else
{
-var a = this.getValidationValue();
+var a = this.trim($F(this.control));
var b = this.trim(this.options.InitialValue);
return(a != b);
}
@@ -500,24 +396,41 @@ return(a != b);
});
Prado.WebUI.TCompareValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
-evaluateIsValid : function()
+_observingComparee : false,
+evaluateIsValid : function(manager)
{
-var value = this.getValidationValue();
+var value = this.trim($F(this.control));
if (value.length <= 0)
return true;
var comparee = $(this.options.ControlToCompare);
if(comparee)
-var compareTo = this.getValidationValue(comparee);
+var compareTo = this.trim($F(comparee));
else
var compareTo = this.options.ValueToCompare || "";
var isValid =this.compare(value, compareTo);
if(comparee)
{
this.updateControlCssClass(comparee, isValid);
-this.observeChanges(comparee);
+this.observeComparee(comparee, manager);
}
return isValid;
},
+observeComparee : function(comparee, manager)
+{
+if(this.options.ObserveChanges != false && !this._observingComparee)
+{
+var validator = this;
+Event.observe(comparee, "change", function()
+{
+if(validator.visible)
+{
+validator.validate(manager);
+manager.updateSummary(validator.group);
+}
+});
+this._observingComparee = true;
+}
+},
compare : function(operand1, operand2)
{
var op1, op2;
@@ -544,9 +457,9 @@ return (op1 == op2);
});
Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
-evaluateIsValid : function()
+evaluateIsValid : function(manager)
{
-var value = this.getValidationValue();
+var value = $F(this.control);
var clientFunction = this.options.ClientValidationFunction;
if(typeof(clientFunction) == "string" && clientFunction.length > 0)
{
@@ -558,9 +471,9 @@ return true;
});
Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
-evaluateIsValid : function()
+evaluateIsValid : function(manager)
{
-var value = this.getValidationValue();
+var value = this.trim($F(this.control));
if(value.length <= 0)
return true;
if(typeof(this.options.DataType) == "undefined")
@@ -568,6 +481,7 @@ this.options.DataType = "String";
var min = this.convert(this.options.DataType, this.options.MinValue || null);
var max = this.convert(this.options.DataType, this.options.MaxValue || null);
value = this.convert(this.options.DataType, value);
+Logger.warn(min+" <= "+value+" <= "+max);
if(value == null)
return false;
var valid = true;
@@ -580,9 +494,9 @@ return valid;
});
Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
-evaluateIsValid : function()
+evaluateIsValid : function(master)
{
-var value = this.getValidationValue();
+var value = this.trim($F(this.control));
if (value.length <= 0)
return true;
var rx = new RegExp(this.options.ValidationExpression);
@@ -591,52 +505,3 @@ return (matches != null && value == matches[0]);
}
});
Prado.WebUI.TEmailAddressValidator = Prado.WebUI.TRegularExpressionValidator;
-Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
-evaluateIsValid : function()
-{
-var elements = this.getListElements();
-if(elements && elements.length <= 0)
-return true;
-this.observeListElements(elements);
-var selection = this.getSelectedValuesAndChecks(elements);
-return this.isValidList(selection.checks, selection.values);
-},
-observeListElements : function(elements)
- {
-if(Prado.Browser().ie && this.isCheckBoxType(elements[0]))
-{
-var validator = this;
-elements.each(function(element)
-{
-validator.observeChanges(element);
-});
-}
- },
-isValidList : function(checked, values)
-{
-var exists = true;
-var required = this.getRequiredValues();
-if(required.length > 0)
-{
-if(values.length < required.length)
-return false;
-required.each(function(requiredValue)
-{
-exists = exists && values.include(requiredValue);
-});
-}
-var min = typeof(this.options.Min) == "undefined" ?
-Number.NEGATIVE_INFINITY : this.options.Min;
-var max = typeof(this.options.Max) == "undefined" ?
-Number.POSITIVE_INFINITY : this.options.Max;
-return exists && checked >= min && checked <= max;
-},
-getRequiredValues : function()
-{
-var required = [];
-if(this.options.Required && this.options.Required.length > 0)
-required = this.options.Required.split(/,\s*/);
-return required;
-}
-});
diff --git a/framework/Web/Javascripts/prado/form.js b/framework/Web/Javascripts/prado/form.js
index 2beb945b..addad893 100644
--- a/framework/Web/Javascripts/prado/form.js
+++ b/framework/Web/Javascripts/prado/form.js
@@ -129,9 +129,9 @@ Prado.PostBack = function(event,options)
$('PRADO_POSTBACK_TARGET').value = options['EventTarget'];
$('PRADO_POSTBACK_PARAMETER').value = options['EventParameter'];
+ Event.fireEvent(form,"submit");
if(options['StopEvent'])
Event.stop(event);
- Event.fireEvent(form,"submit");
}
/*
diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js
index 4c189532..10169aab 100644
--- a/framework/Web/Javascripts/prado/validation3.js
+++ b/framework/Web/Javascripts/prado/validation3.js
@@ -1,58 +1,6 @@
/**
- * Prado client-side javascript validation fascade.
- *
- * There are 4 basic classes, Validation, ValidationManager, ValidationSummary
- * and TBaseValidator, that interact together to perform validation.
- * The <tt>Prado.Validation</tt> class co-ordinates together the
- * validation scheme and is responsible for maintaining references
- * to ValidationManagers.
- *
- * The ValidationManager class is responsible for maintaining refereneces
- * to individual validators, validation summaries and their associated
- * groupings.
- *
- * The ValidationSummary take cares of display the validator error messages
- * as html output or an alert output.
- *
- * The TBaseValidator is the base class for all validators and contains
- * methods to interact with the actual inputs, data type conversion.
- *
- * An instance of ValidationManager must be instantiated first for a
- * particular form before instantiating validators and summaries.
- *
- * Usage example: adding a required field to a text box input with
- * ID "input1" in a form with ID "form1".
- * <code>
- * <script type="text/javascript" src="../prado.js"></script>
- * <script type="text/javascript" src="../validator.js"></script>
- * <form id="form1" action="...">
- * <div>
- * <input type="text" id="input1" />
- * <span id="validator1" style="display:none; color:red">*</span>
- * <input type="submit text="submit" />
- * <script type="text/javascript">
- * new Prado.ValidationManager({FormID : 'form1'});
- * var options =
- * {
- * ID : 'validator1',
- * FormID : 'form1',
- * ErrorMessage : '*',
- * ControlToValidate : 'input1'
- * }
- * new Prado.WebUI.TRequiredFieldValidator(options);
- * new Prado.WebUI.TValidationSummary({ID:'summary1',FormID:'form1'});
- *
- * //watch the form onsubmit event, check validators, stop if not valid.
- * Event.observe("form1", "submit" function(ev)
- * {
- * if(Prado.WebUI.Validation.isValid("form1") == false)
- * Event.stop(ev);
- * });
- * </script>
- * </div>
- * </form>
- * </code>
+ * Prado client-side javascript validation manager.
*/
Prado.Validation = Class.create();
@@ -106,7 +54,6 @@ Object.extend(Prado.Validation,
* Add a new validator to a particular form.
* @param string the form that the validator belongs.
* @param object a validator
- * @return object the manager
*/
addValidator : function(formID, validator)
{
@@ -114,14 +61,12 @@ Object.extend(Prado.Validation,
this.managers[formID].addValidator(validator);
else
throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
- return this.managers[formID];
},
/**
* Add a new validation summary.
* @param string the form that the validation summary belongs.
* @param object a validation summary
- * @return object manager
*/
addSummary : function(formID, validator)
{
@@ -129,19 +74,14 @@ Object.extend(Prado.Validation,
this.managers[formID].addSummary(validator);
else
throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
- return this.managers[formID];
}
});
-Prado.ValidationManager = Class.create();
/**
* Validation manager instances. Manages validators for a particular
- * HTML form. The manager contains references to all the validators
- * summaries, and their groupings for a particular form.
- * Generally, <tt>Prado.Validation</tt> methods should be called rather
- * than calling directly the ValidationManager.
+ * HTML form.
*/
-Prado.ValidationManager.prototype =
+Prado.Validation.prototype =
{
validators : [], // list of validators
summaries : [], // validation summaries
@@ -180,12 +120,13 @@ Prado.ValidationManager.prototype =
_validateGroup: function(groupID)
{
var valid = true;
+ var manager = this;
if(this.groups.include(groupID))
{
this.validators.each(function(validator)
{
if(validator.group == groupID)
- valid = valid & validator.validate();
+ valid = valid & validator.validate(manager);
else
validator.hide();
});
@@ -201,10 +142,11 @@ Prado.ValidationManager.prototype =
_validateNonGroup : function()
{
var valid = true;
+ var manager = this;
this.validators.each(function(validator)
{
if(!validator.group)
- valid = valid & validator.validate();
+ valid = valid & validator.validate(manager);
else
validator.hide();
});
@@ -520,9 +462,8 @@ Prado.WebUI.TBaseValidator.prototype =
visible : false,
isValid : true,
options : {},
- _isObserving : {},
+ _isObserving : false,
group : null,
- manager : null,
/**
* <code>
@@ -552,7 +493,7 @@ Prado.WebUI.TBaseValidator.prototype =
this.message = $(options.ID);
this.group = options.ValidationGroup;
- this.manager = Prado.Validation.addValidator(options.FormID, this);
+ Prado.Validation.addValidator(options.FormID, this);
},
/**
@@ -577,8 +518,7 @@ Prado.WebUI.TBaseValidator.prototype =
this.message.style.visibility = this.isValid ? "hidden" : "visible";
}
- if(this.control)
- this.updateControlCssClass(this.control, this.isValid);
+ this.updateControlCssClass(this.control, this.isValid);
if(this.options.FocusOnError && !this.isValid)
Prado.Element.focus(this.options.FocusElementID);
@@ -617,23 +557,24 @@ Prado.WebUI.TBaseValidator.prototype =
/**
* Calls evaluateIsValid() function to set the value of isValid property.
* Triggers onValidate event and onSuccess or onError event.
+ * @param Validation manager
* @return boolean true if valid.
*/
- validate : function()
+ validate : function(manager)
{
if(this.enabled)
- this.isValid = this.evaluateIsValid();
+ this.isValid = this.evaluateIsValid(manager);
- this.options.OnValidate(this);
+ this.options.OnValidate(this, manager);
this.updateControl();
if(this.isValid)
- this.options.OnSuccess(this);
+ this.options.OnSuccess(this, manager);
else
- this.options.OnError(this);
-
- this.observeChanges(this.control);
+ this.options.OnError(this, manager);
+
+ this.observeChanges(manager);
return this.isValid;
},
@@ -641,28 +582,21 @@ Prado.WebUI.TBaseValidator.prototype =
/**
* Observe changes to the control input, re-validate upon change. If
* the validator is not visible, no updates are propagated.
- * @param HTMLElement control to observe changes
*/
- observeChanges : function(control)
+ observeChanges : function(manager)
{
- if(!control) return;
-
- var canObserveChanges = this.options.ObserveChanges != false;
- var currentlyObserving = this._isObserving[control.id+this.options.ID];
-
- if(canObserveChanges && !currentlyObserving)
+ if(this.options.ObserveChanges != false && !this._isObserving)
{
var validator = this;
-
- Event.observe(control, 'change', function()
+ Event.observe(this.control, 'change', function()
{
if(validator.visible)
{
- validator.validate();
- validator.manager.updateSummary(validator.group);
+ validator.validate(manager);
+ manager.updateSummary(validator.group);
}
});
- this._isObserving[control.id+this.options.ID] = true;
+ this._isObserving = true;
}
},
@@ -676,14 +610,14 @@ Prado.WebUI.TBaseValidator.prototype =
/**
* Convert the value to a specific data type.
- * @param {string} the data type, "Integer", "Double", "Date" or "String"
+ * @param {string} the data type, "Integer", "Double", "Currency", "Date" or "String"
* @param {string} the value to convert.
* @type {mixed|null} the converted data value.
*/
convert : function(dataType, value)
{
if(typeof(value) == "undefined")
- value = this.getValidationValue();
+ value = $F(this.control);
var string = new String(value);
switch(dataType)
{
@@ -692,149 +626,18 @@ Prado.WebUI.TBaseValidator.prototype =
case "Double" :
case "Float" :
return string.toDouble(this.options.DecimalChar);
+ case "Currency" :
+ return string.toCurrency(this.options.GroupChar, this.options.Digits, this.options.DecimalChar);
case "Date":
- if(typeof(value) != "string")
- return value;
+ var value = string.toDate(this.options.DateFormat);
+ if(value && typeof(value.getTime) == "function")
+ return value.getTime();
else
- {
- var value = string.toDate(this.options.DateFormat);
- if(value && typeof(value.getTime) == "function")
- return value.getTime();
- else
- return null;
- }
+ return null;
case "String":
return string.toString();
}
return value;
- },
-
- /**
- * @return mixed control value to validate
- */
- getValidationValue : function(control)
- {
- if(!control)
- control = this.control
- switch(this.options.ControlType)
- {
- case 'TDatePicker':
- if(control.type == "text")
- return this.trim($F(control));
- else
- {
- this.observeDatePickerChanges();
-
- return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();
- }
- default:
- if(this.isListControlType())
- return this.getFirstSelectedListValue();
- else
- return this.trim($F(control));
- }
- },
-
- /**
- * Observe changes in the drop down list date picker, IE only.
- */
- observeDatePickerChanges : function()
- {
- if(Prado.Browser().ie)
- {
- var DatePicker = Prado.WebUI.TDatePicker;
- this.observeChanges(DatePicker.getDayListControl(this.control));
- this.observeChanges(DatePicker.getMonthListControl(this.control));
- this.observeChanges(DatePicker.getYearListControl(this.control));
- }
- },
-
- /**
- * Gets numeber selections and their values.
- * @return object returns selected values in <tt>values</tt> property
- * and number of selections in <tt>checks</tt> property.
- */
- getSelectedValuesAndChecks : function(elements, initialValue)
- {
- var checked = 0;
- var values = [];
- var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
- elements.each(function(element)
- {
- if(element[isSelected] && element.value != initialValue)
- {
- checked++;
- values.push(element.value);
- }
- });
- return {'checks' : checked, 'values' : values};
- },
-
- /**
- * Gets an array of the list control item input elements, for TCheckBoxList
- * checkbox inputs are returned, for TListBox HTML option elements are returned.
- * @return array list control option elements.
- */
- getListElements : function()
- {
- switch(this.options.ControlType)
- {
- case 'TCheckBoxList': case 'TRadioButtonList':
- var elements = [];
- for(var i = 0; i < this.options.TotalItems; i++)
- {
- var element = $(this.options.ControlToValidate+"_"+i);
- if(this.isCheckBoxType(element))
- elements.push(element);
- }
- return elements;
- case 'TListBox':
- var elements = [];
- var element = $(this.options.ControlToValidate);
- if(element && (type = element.type.toLowerCase()))
- {
- if(type == "select-one" || type == "select-multiple")
- elements = $A(element.options);
- }
- return elements;
- default:
- return [];
- }
- },
-
- /**
- * @return boolean true if element is of checkbox or radio type.
- */
- isCheckBoxType : function(element)
- {
- if(element && element.type)
- {
- var type = element.type.toLowerCase();
- return type == "checkbox" || type == "radio";
- }
- return false;
- },
-
- /**
- * @return boolean true if control to validate is of some of the TListControl type.
- */
- isListControlType : function()
- {
- var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
- return list.include(this.options.ControlType);
- },
-
- /**
- * @return string gets the first selected list value, initial value if none found.
- */
- getFirstSelectedListValue : function()
- {
- var initial = "";
- if(typeof(this.options.InitialValue) != "undefined")
- initial = this.options.InitialValue;
- var elements = this.getListElements();
- var selection = this.getSelectedValuesAndChecks(elements, initial);
- return selection.values.length > 0 ? selection.values[0] : initial;
}
}
@@ -861,7 +664,7 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator,
}
else
{
- var a = this.getValidationValue();
+ var a = this.trim($F(this.control));
var b = this.trim(this.options.InitialValue);
return(a != b);
}
@@ -883,6 +686,7 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator,
* type before the comparison operation is performed. The following value types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The format can be by the <tt>DateFormat</tt> option.
* - <b>String</b> A string data type.
*
@@ -899,35 +703,57 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator,
*/
Prado.WebUI.TCompareValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
- //_observingComparee : false,
+ _observingComparee : false,
/**
* Compares the input to another input or a given value.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(manager)
{
- var value = this.getValidationValue();
+ var value = this.trim($F(this.control));
if (value.length <= 0)
return true;
var comparee = $(this.options.ControlToCompare);
if(comparee)
- var compareTo = this.getValidationValue(comparee);
+ var compareTo = this.trim($F(comparee));
else
- var compareTo = this.options.ValueToCompare || "";
+ var compareTo = this.options.ValueToCompare || "";
var isValid = this.compare(value, compareTo);
if(comparee)
{
this.updateControlCssClass(comparee, isValid);
- this.observeChanges(comparee);
+ this.observeComparee(comparee, manager);
}
return isValid;
},
/**
+ * Observe the comparee input element for changes.
+ * @param object HTML input element to observe
+ * @param object Validation manager.
+ */
+ observeComparee : function(comparee, manager)
+ {
+ if(this.options.ObserveChanges != false && !this._observingComparee)
+ {
+ var validator = this;
+ Event.observe(comparee, "change", function()
+ {
+ if(validator.visible)
+ {
+ validator.validate(manager);
+ manager.updateSummary(validator.group);
+ }
+ });
+ this._observingComparee = true;
+ }
+ },
+
+ /**
* Compares two values, their values are casted to type defined
* by <tt>DataType</tt> option. False is returned if the first
* operand converts to null. Returns true if the second operand
@@ -990,9 +816,9 @@ Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
/**
* Calls custom validation function.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(manager)
{
- var value = this.getValidationValue();
+ var value = $F(this.control);
var clientFunction = this.options.ClientValidationFunction;
if(typeof(clientFunction) == "string" && clientFunction.length > 0)
{
@@ -1014,6 +840,7 @@ Prado.WebUI.TCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
* operation is performed. The following value types are supported:
* - <b>Integer</b> A 32-bit signed integer data type.
* - <b>Float</b> A double-precision floating point number data type.
+ * - <b>Currency</b> A decimal data type that can contain currency symbols.
* - <b>Date</b> A date data type. The date format can be specified by
* setting <tt>DateFormat</tt> option, which must be recognizable
* by <tt>Date.SimpleParse</tt> javascript function.
@@ -1029,11 +856,11 @@ Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator,
{
/**
* Compares the input value with a minimum and/or maximum value.
- * @return boolean true if the value is empty, returns false if conversion fails.
+ * Returns true if the value is empty, returns false if conversion fails.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(manager)
{
- var value = this.getValidationValue();
+ var value = this.trim($F(this.control));
if(value.length <= 0)
return true;
if(typeof(this.options.DataType) == "undefined")
@@ -1043,6 +870,8 @@ Prado.WebUI.TRangeValidator = Class.extend(Prado.WebUI.TBaseValidator,
var max = this.convert(this.options.DataType, this.options.MaxValue || null);
value = this.convert(this.options.DataType, value);
+ Logger.warn(min+" <= "+value+" <= "+max);
+
if(value == null)
return false;
@@ -1068,9 +897,9 @@ Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidato
/**
* Compare the control input against a regular expression.
*/
- evaluateIsValid : function()
+ evaluateIsValid : function(master)
{
- var value = this.getValidationValue();
+ var value = this.trim($F(this.control));
if (value.length <= 0)
return true;
@@ -1087,84 +916,3 @@ Prado.WebUI.TRegularExpressionValidator = Class.extend(Prado.WebUI.TBaseValidato
Prado.WebUI.TEmailAddressValidator = Prado.WebUI.TRegularExpressionValidator;
-/**
- * TListControlValidator checks the number of selection and their values
- * for a TListControl that allows multiple selections.
- */
-Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator,
-{
- /**
- * @return true if the number of selections and/or their values
- * match the requirements.
- */
- evaluateIsValid : function()
- {
- var elements = this.getListElements();
- if(elements && elements.length <= 0)
- return true;
-
- this.observeListElements(elements);
-
- var selection = this.getSelectedValuesAndChecks(elements);
- return this.isValidList(selection.checks, selection.values);
- },
-
- /**
- * Observe list elements for IE browsers of changes
- */
- observeListElements : function(elements)
- {
- if(Prado.Browser().ie && this.isCheckBoxType(elements[0]))
- {
- var validator = this;
- elements.each(function(element)
- {
- validator.observeChanges(element);
- });
- }
- },
-
- /**
- * Determine if the number of checked and the checked values
- * satisfy the required number of checks and/or the checked values
- * equal to the required values.
- * @return boolean true if checked values and number of checks are satisfied.
- */
- isValidList : function(checked, values)
- {
- var exists = true;
-
- //check the required values
- var required = this.getRequiredValues();
- if(required.length > 0)
- {
- if(values.length < required.length)
- return false;
- required.each(function(requiredValue)
- {
- exists = exists && values.include(requiredValue);
- });
- }
-
- var min = typeof(this.options.Min) == "undefined" ?
- Number.NEGATIVE_INFINITY : this.options.Min;
- var max = typeof(this.options.Max) == "undefined" ?
- Number.POSITIVE_INFINITY : this.options.Max;
- return exists && checked >= min && checked <= max;
- },
-
- /**
- * @return array list of required options that must be selected.
- */
- getRequiredValues : function()
- {
- var required = [];
- if(this.options.Required && this.options.Required.length > 0)
- required = this.options.Required.split(/,\s*/);
- return required;
- }
-});
-
-
-
-