summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/Javascripts/js/compressed/validator.js30
-rw-r--r--framework/Web/Javascripts/js/debug/validator.js46
-rw-r--r--framework/Web/Javascripts/prado/validator/validation3.js46
-rw-r--r--framework/Web/UI/ActiveControls/TActivePageAdapter.php1
-rw-r--r--framework/Web/UI/TClientScriptManager.php1
-rw-r--r--framework/Web/UI/TControl.php10
-rw-r--r--framework/Web/UI/WebControls/TButton.php21
-rw-r--r--framework/Web/UI/WebControls/TImageButton.php19
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php16
9 files changed, 134 insertions, 56 deletions
diff --git a/framework/Web/Javascripts/js/compressed/validator.js b/framework/Web/Javascripts/js/compressed/validator.js
index 49316113..0571b27b 100644
--- a/framework/Web/Javascripts/js/compressed/validator.js
+++ b/framework/Web/Javascripts/js/compressed/validator.js
@@ -76,7 +76,7 @@ this.messages.show();this.visible=true;},formats:function(type)
{switch(this.options.DisplayMode)
{case"List":output+=messages[i]+"\n";break;case"BulletList":default:output+=" - "+messages[i]+"\n";break;case"SingleParagraph":output+=messages[i]+" ";break;}}
return output;}};Prado.WebUI.TBaseValidator=Class.create();Prado.WebUI.TBaseValidator.prototype={initialize:function(options)
-{this.enabled=true;this.visible=false;this.isValid=true;this._isObserving={};this.group=null;this.requestDispatched=false;this.options=options;this.control=$(options.ControlToValidate);this.message=$(options.ID);if(this.control&&this.message)
+{this.enabled=true;this.visible=false;this.isValid=true;this._isObserving={};this.group=null;this.options=options;this.control=$(options.ControlToValidate);this.message=$(options.ID);if(this.control&&this.message)
{this.group=options.ValidationGroup;this.manager=Prado.Validation.addValidator(options.FormID,this);}},getErrorMessage:function()
{return this.options.ErrorMessage;},updateControl:function(focus)
{this.refreshControlAndMessage();if(this.options.FocusOnError&&!this.isValid)
@@ -96,23 +96,20 @@ control.addClassName(CssClass);}},hide:function()
this.control=$(this.options.ControlToValidate);if(!this.control)
{this.isValid=true;return this.isValid;}
if(typeof(this.options.OnValidate)=="function")
-{if(this.requestDispatched==false)
-this.options.OnValidate(this,invoker);}
+{this.options.OnValidate(this,invoker);}
if(this.enabled)
this.isValid=this.evaluateIsValid();else
-this.isValid=true;if(this.isValid)
+this.isValid=true;this.updateValidationDisplay(invoker);this.observeChanges(this.control);return this.isValid;},updateValidationDisplay:function(invoker)
+{if(this.isValid)
{if(typeof(this.options.OnValidationSuccess)=="function")
-{if(this.requestDispatched==false)
-{this.refreshControlAndMessage();this.options.OnValidationSuccess(this,invoker);}}
+{this.refreshControlAndMessage();this.options.OnValidationSuccess(this,invoker);}
else
this.updateControl();}
else
{if(typeof(this.options.OnValidationError)=="function")
-{if(this.requestDispatched==false)
-{this.refreshControlAndMessage();this.options.OnValidationError(this,invoker)}}
+{this.refreshControlAndMessage();this.options.OnValidationError(this,invoker)}
else
-this.updateControl();}
-this.observeChanges(this.control);return this.isValid;},observeChanges:function(control)
+this.updateControl();}},observeChanges:function(control)
{if(!control)return;var canObserveChanges=this.options.ObserveChanges!=false;var currentlyObserving=this._isObserving[control.id+this.options.ID];if(canObserveChanges&&!currentlyObserving)
{var validator=this;Event.observe(control,'change',function()
{if(validator.visible)
@@ -136,7 +133,7 @@ switch(this.options.ControlType)
else
return value;}
else
-{this.observeDatePickerChanges();return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();}
+{this.observeDatePickerChanges();return Prado.WebUI.TDatePicker.getDropDownDate(control);}
case'THtmlArea':if(typeof tinyMCE!="undefined")
tinyMCE.triggerSave();return this.trim($F(control));case'TRadioButton':if(this.options.GroupName)
return this.getRadioButtonGroupValue();default:if(this.isListControlType())
@@ -182,12 +179,13 @@ return true;switch(this.options.Operator)
{var value=this.getValidationValue();var clientFunction=this.options.ClientValidationFunction;if(typeof(clientFunction)=="string"&&clientFunction.length>0)
{validate=clientFunction.toFunction();return validate(this,value);}
return true;}});Prado.WebUI.TActiveCustomValidator=Class.extend(Prado.WebUI.TBaseValidator,{validatingValue:null,evaluateIsValid:function()
-{value=this.getValidationValue();if(!this.requestDispatched&&value!=this.validatingValue)
-{this.validatingValue=value;request=new Prado.CallbackRequest(this.options.EventTarget,this.options);request.setCallbackParameter(value);request.setCausesValidation(false);request.options.onSuccess=this.callbackOnSuccess.bind(this);request.options.onFailure=this.callbackOnFailure.bind(this);request.dispatch();this.requestDispatched=true;return false;}
+{value=this.getValidationValue();if((""+value)!=(""+this.validatingValue))
+{this.validatingValue=value;request=new Prado.CallbackRequest(this.options.EventTarget,this.options);if(this.options.DateFormat&&value instanceof Date)
+value=value.SimpleFormat(this.options.DateFormat);request.setCallbackParameter(value);request.setCausesValidation(false);request.options.onSuccess=this.callbackOnSuccess.bind(this);request.options.onFailure=this.callbackOnFailure.bind(this);request.dispatch();return false;}
return this.isValid;},callbackOnSuccess:function(request,data)
-{this.isValid=data;this.requestDispatched=false;if(typeof(this.options.onSuccess)=="function")
-this.options.onSuccess(request,data);Prado.Validation.validate(this.options.FormID,this.group,null);},callbackOnFailure:function(request,data)
-{this.requestDispatched=false;if(typeof(this.options.onFailure)=="function")
+{this.isValid=data;if(typeof(this.options.onSuccess)=="function")
+this.options.onSuccess(request,data);this.updateValidationDisplay();},callbackOnFailure:function(request,data)
+{if(typeof(this.options.onFailure)=="function")
this.options.onFailure(request,data);}});Prado.WebUI.TRangeValidator=Class.extend(Prado.WebUI.TBaseValidator,{evaluateIsValid:function()
{var value=this.getValidationValue();if(value.length<=0)
return true;if(typeof(this.options.DataType)=="undefined")
diff --git a/framework/Web/Javascripts/js/debug/validator.js b/framework/Web/Javascripts/js/debug/validator.js
index 179963f4..7d17eeda 100644
--- a/framework/Web/Javascripts/js/debug/validator.js
+++ b/framework/Web/Javascripts/js/debug/validator.js
@@ -571,7 +571,7 @@ Prado.WebUI.TBaseValidator.prototype =
this.isValid = true;
this._isObserving = {};
this.group = null;
- this.requestDispatched = false;
+ //this.requestDispatched = false;
this.options = options;
this.control = $(options.ControlToValidate);
@@ -676,7 +676,7 @@ Prado.WebUI.TBaseValidator.prototype =
if(typeof(this.options.OnValidate) == "function")
{
- if(this.requestDispatched == false)
+ //if(this.requestDispatched == false)
this.options.OnValidate(this, invoker);
}
@@ -685,15 +685,26 @@ Prado.WebUI.TBaseValidator.prototype =
else
this.isValid = true;
+ this.updateValidationDisplay(invoker);
+ this.observeChanges(this.control);
+
+ return this.isValid;
+ },
+
+ /**
+ * Updates the validation messages, update the control to be validated.
+ */
+ updateValidationDisplay : function(invoker)
+ {
if(this.isValid)
{
if(typeof(this.options.OnValidationSuccess) == "function")
{
- if(this.requestDispatched == false)
- {
+ //if(this.requestDispatched == false)
+ //{
this.refreshControlAndMessage();
this.options.OnValidationSuccess(this, invoker);
- }
+ //}
}
else
this.updateControl();
@@ -702,19 +713,15 @@ Prado.WebUI.TBaseValidator.prototype =
{
if(typeof(this.options.OnValidationError) == "function")
{
- if(this.requestDispatched == false)
- {
+ //if(this.requestDispatched == false)
+ //{
this.refreshControlAndMessage();
this.options.OnValidationError(this, invoker)
- }
+ //}
}
else
this.updateControl();
}
-
- this.observeChanges(this.control);
-
- return this.isValid;
},
/**
@@ -816,7 +823,7 @@ Prado.WebUI.TBaseValidator.prototype =
{
this.observeDatePickerChanges();
- return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();
+ return Prado.WebUI.TDatePicker.getDropDownDate(control);//.getTime();
}
case 'THtmlArea':
if(typeof tinyMCE != "undefined")
@@ -1126,16 +1133,19 @@ Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
evaluateIsValid : function()
{
value = this.getValidationValue();
- if(!this.requestDispatched && value != this.validatingValue)
+ //if(!this.requestDispatched && (""+value) != (""+this.validatingValue))
+ if((""+value) != (""+this.validatingValue))
{
this.validatingValue = value;
request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ if(this.options.DateFormat && value instanceof Date) //change date to string with formatting.
+ value = value.SimpleFormat(this.options.DateFormat);
request.setCallbackParameter(value);
request.setCausesValidation(false);
request.options.onSuccess = this.callbackOnSuccess.bind(this);
request.options.onFailure = this.callbackOnFailure.bind(this);
request.dispatch();
- this.requestDispatched = true;
+// this.requestDispatched = true;
return false;
}
return this.isValid;
@@ -1144,15 +1154,15 @@ Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
callbackOnSuccess : function(request, data)
{
this.isValid = data;
- this.requestDispatched = false;
+// this.requestDispatched = false;
if(typeof(this.options.onSuccess) == "function")
this.options.onSuccess(request,data);
- Prado.Validation.validate(this.options.FormID, this.group,null);
+ this.updateValidationDisplay();
},
callbackOnFailure : function(request, data)
{
- this.requestDispatched = false;
+// this.requestDispatched = false;
if(typeof(this.options.onFailure) == "function")
this.options.onFailure(request,data);
}
diff --git a/framework/Web/Javascripts/prado/validator/validation3.js b/framework/Web/Javascripts/prado/validator/validation3.js
index 9b5b4046..5fa879a5 100644
--- a/framework/Web/Javascripts/prado/validator/validation3.js
+++ b/framework/Web/Javascripts/prado/validator/validation3.js
@@ -571,7 +571,7 @@ Prado.WebUI.TBaseValidator.prototype =
this.isValid = true;
this._isObserving = {};
this.group = null;
- this.requestDispatched = false;
+ //this.requestDispatched = false;
this.options = options;
this.control = $(options.ControlToValidate);
@@ -676,7 +676,7 @@ Prado.WebUI.TBaseValidator.prototype =
if(typeof(this.options.OnValidate) == "function")
{
- if(this.requestDispatched == false)
+ //if(this.requestDispatched == false)
this.options.OnValidate(this, invoker);
}
@@ -685,15 +685,26 @@ Prado.WebUI.TBaseValidator.prototype =
else
this.isValid = true;
+ this.updateValidationDisplay(invoker);
+ this.observeChanges(this.control);
+
+ return this.isValid;
+ },
+
+ /**
+ * Updates the validation messages, update the control to be validated.
+ */
+ updateValidationDisplay : function(invoker)
+ {
if(this.isValid)
{
if(typeof(this.options.OnValidationSuccess) == "function")
{
- if(this.requestDispatched == false)
- {
+ //if(this.requestDispatched == false)
+ //{
this.refreshControlAndMessage();
this.options.OnValidationSuccess(this, invoker);
- }
+ //}
}
else
this.updateControl();
@@ -702,19 +713,15 @@ Prado.WebUI.TBaseValidator.prototype =
{
if(typeof(this.options.OnValidationError) == "function")
{
- if(this.requestDispatched == false)
- {
+ //if(this.requestDispatched == false)
+ //{
this.refreshControlAndMessage();
this.options.OnValidationError(this, invoker)
- }
+ //}
}
else
this.updateControl();
}
-
- this.observeChanges(this.control);
-
- return this.isValid;
},
/**
@@ -816,7 +823,7 @@ Prado.WebUI.TBaseValidator.prototype =
{
this.observeDatePickerChanges();
- return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();
+ return Prado.WebUI.TDatePicker.getDropDownDate(control);//.getTime();
}
case 'THtmlArea':
if(typeof tinyMCE != "undefined")
@@ -1126,16 +1133,19 @@ Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
evaluateIsValid : function()
{
value = this.getValidationValue();
- if(!this.requestDispatched && value != this.validatingValue)
+ //if(!this.requestDispatched && (""+value) != (""+this.validatingValue))
+ if((""+value) != (""+this.validatingValue))
{
this.validatingValue = value;
request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
+ if(this.options.DateFormat && value instanceof Date) //change date to string with formatting.
+ value = value.SimpleFormat(this.options.DateFormat);
request.setCallbackParameter(value);
request.setCausesValidation(false);
request.options.onSuccess = this.callbackOnSuccess.bind(this);
request.options.onFailure = this.callbackOnFailure.bind(this);
request.dispatch();
- this.requestDispatched = true;
+// this.requestDispatched = true;
return false;
}
return this.isValid;
@@ -1144,15 +1154,15 @@ Prado.WebUI.TActiveCustomValidator = Class.extend(Prado.WebUI.TBaseValidator,
callbackOnSuccess : function(request, data)
{
this.isValid = data;
- this.requestDispatched = false;
+// this.requestDispatched = false;
if(typeof(this.options.onSuccess) == "function")
this.options.onSuccess(request,data);
- Prado.Validation.validate(this.options.FormID, this.group,null);
+ this.updateValidationDisplay();
},
callbackOnFailure : function(request, data)
{
- this.requestDispatched = false;
+// this.requestDispatched = false;
if(typeof(this.options.onFailure) == "function")
this.options.onFailure(request,data);
}
diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
index da53856a..ea5d673b 100644
--- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php
+++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php
@@ -15,6 +15,7 @@
*/
Prado::using('System.Web.UI.ActiveControls.TCallbackResponseAdapter');
Prado::using('System.Web.UI.ActiveControls.TCallbackClientScript');
+Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
/**
* TActivePageAdapter class.
diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php
index 8870666e..a319595d 100644
--- a/framework/Web/UI/TClientScriptManager.php
+++ b/framework/Web/UI/TClientScriptManager.php
@@ -238,6 +238,7 @@ class TClientScriptManager extends TApplicationComponent
*/
public function registerDefaultButton($panel, $button)
{
+ $button->setIsDefaultButton(true);
$options = TJavaScript::encode($this->getDefaultButtonOptions($panel, $button));
$code = "new Prado.WebUI.DefaultButton($options);";
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 85770cb4..68e10c6e 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -2089,6 +2089,16 @@ interface IButtonControl
* @param TCommandEventParameter event parameter to be passed to the event handlers
*/
public function onCommand($param);
+
+ /**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value);
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton();
}
/**
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index aa4e21a7..9f2b2825 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -131,12 +131,29 @@ class TButton extends TWebControl implements IPostBackEventHandler, IButtonContr
}
/**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value)
+ {
+ $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton()
+ {
+ return $this->getViewState('IsDefaultButton', false);
+ }
+
+ /**
* @return boolean whether the button needs javascript to do postback
*/
protected function needPostBackScript()
{
- //IE needs JS to be rendered for default button to work if no validators are assigned to this button
- return $this->canCauseValidation() || $this->hasEventHandler('OnClick') || $this->hasEventHandler('OnCommand');
+ return $this->canCauseValidation() || ($this->getButtonType()!==TButtonType::Submit &&
+ ($this->hasEventHandler('OnClick') || $this->hasEventHandler('OnCommand')))
+ || $this->getIsDefaultButton();
}
/**
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php
index 41de5087..44d4c14b 100644
--- a/framework/Web/UI/WebControls/TImageButton.php
+++ b/framework/Web/UI/WebControls/TImageButton.php
@@ -148,12 +148,27 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven
}
/**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value)
+ {
+ $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton()
+ {
+ return $this->getViewState('IsDefaultButton', false);
+ }
+
+ /**
* @return boolean whether the button needs javascript to do postback
*/
protected function needPostBackScript()
{
- //IE needs JS to be rendered for default button to work if no validators are assigned to this button
- return $this->canCauseValidation() || $this->hasEventHandler('OnClick') || $this->hasEventHandler('OnCommand');
+ return $this->canCauseValidation() || $this->getIsDefaultButton();
}
/**
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index d993b9f5..f92dded3 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -116,6 +116,22 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler, IButtonC
}
/**
+ * @param boolean set by a panel to register this button as the default button for the panel.
+ */
+ public function setIsDefaultButton($value)
+ {
+ $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean true if this button is registered as a default button for a panel.
+ */
+ public function getIsDefaultButton()
+ {
+ return $this->getViewState('IsDefaultButton', false);
+ }
+
+ /**
* Renders the Href for link button.
* @param THtmlWriter renderer
*/