summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls
diff options
context:
space:
mode:
authorxue <>2005-12-07 03:31:08 +0000
committerxue <>2005-12-07 03:31:08 +0000
commitd2f675e58b1c42c8960907ee20490a391aec0ecc (patch)
treeec37e7019b5ea261b4dde1ac88b2dacbd0675905 /framework/Web/UI/WebControls
parentbd56fe6028fc09d8121f353ac7e33fc11994de9b (diff)
Diffstat (limited to 'framework/Web/UI/WebControls')
-rw-r--r--framework/Web/UI/WebControls/TButton.php3
-rw-r--r--framework/Web/UI/WebControls/TImageButton.php3
-rw-r--r--framework/Web/UI/WebControls/TLinkButton.php2
-rw-r--r--framework/Web/UI/WebControls/TTextBox.php126
4 files changed, 61 insertions, 73 deletions
diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php
index a9eac8ac..e7c40a75 100644
--- a/framework/Web/UI/WebControls/TButton.php
+++ b/framework/Web/UI/WebControls/TButton.php
@@ -81,8 +81,7 @@ class TButton extends TWebControl implements IPostBackEventHandler
if($this->getEnabled(true))
{
- $onclick='';
- $onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):'';
+ $onclick=$this->removeAttribute('onclick');
$onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
$onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),false);
if(!empty($onclick))
diff --git a/framework/Web/UI/WebControls/TImageButton.php b/framework/Web/UI/WebControls/TImageButton.php
index 669e517e..33dfde75 100644
--- a/framework/Web/UI/WebControls/TImageButton.php
+++ b/framework/Web/UI/WebControls/TImageButton.php
@@ -96,8 +96,7 @@ class TImageButton extends TImage implements IPostBackDataHandler, IPostBackEven
if($this->getEnabled(true))
{
- $onclick='';
- $onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):'';
+ $onclick=$this->removeAttribute('onclick');
$onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
$onclick.=$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),false);
if(!empty($onclick))
diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php
index d3be1ade..dd2d8cb7 100644
--- a/framework/Web/UI/WebControls/TLinkButton.php
+++ b/framework/Web/UI/WebControls/TLinkButton.php
@@ -79,7 +79,7 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler
{
$page=$this->getPage();
$page->ensureRenderInForm($this);
- $onclick=$this->hasAttribute('onclick')?$this->getAttributes()->remove('onclick'):'';
+ $onclick=$this->removeAttribute('onclick');
$onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick());
if(!empty($onclick))
$writer->addAttribute('onclick','javascript:'.$onclick);
diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php
index 4d4fcff6..3e5f0107 100644
--- a/framework/Web/UI/WebControls/TTextBox.php
+++ b/framework/Web/UI/WebControls/TTextBox.php
@@ -14,22 +14,26 @@
* TTextBox class
*
* TTextBox displays a text box on the Web page for user input.
- * The text displayed in the TTextBox control is determined by the <b>Text</b> property.
- * You can create a <b>SingleLine</b>, a <b>MultiLine</b>, or a <b>Password</b> text box
- * by setting the <b>TextMode</b> property.
- * If the TTextBox control is a multiline text box, the number of rows
- * it displays is determined by the <b>Rows</b> property, and the <b>Wrap</b> property
+ * The text displayed in the TTextBox control is determined by the
+ * {@link setText Text} property. You can create a <b>SingleLine</b>,
+ * a <b>MultiLine</b>, or a <b>Password</b> text box by setting
+ * the {@link setTextMode TextMode} property. If the TTextBox control
+ * is a multiline text box, the number of rows it displays is determined
+ * by the {@link setRows Rows} property, and the {@link setWrap Wrap} property
* can be used to determine whether to wrap the text in the component.
*
- * To specify the display width of the text box, in characters, set the <b>Columns</b> property.
- * To prevent the text displayed in the component from being modified,
- * set the <b>ReadOnly</b> property to true. If you want to limit the user input
- * to a specified number of characters, set the <b>MaxLength</b> property. To use AutoComplete
- * feature, set the <b>AutoCompleteType</b> property.
+ * To specify the display width of the text box, in characters, set
+ * the {@link setColumns Columns} property. To prevent the text displayed
+ * in the component from being modified, set the {@link setReadOnly ReadOnly}
+ * property to true. If you want to limit the user input to a specified number
+ * of characters, set the {@link setMaxLength MaxLength} property.
+ * To use AutoComplete feature, set the {@link setAutoCompleteType AutoCompleteType} property.
*
- * If <b>AutoPostBack</b> is set true, updating the text box and then changing the focus out of it
- * will cause postback action. And if <b>CausesValidation</b> is true, validation will also
- * be processed, which can be further restricted within a <b>ValidationGroup</b>.
+ * If {@link setAutoPostBack AutoPostBack} is set true, updating the text box
+ * and then changing the focus out of it will cause postback action.
+ * And if {@link setCausesValidation CausesValidation} is true, validation will
+ * also be processed, which can be further restricted within
+ * a {@link setValidationGroup ValidationGroup}.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -39,6 +43,11 @@
class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
{
/**
+ * @var array list of auto complete types
+ */
+ private static $_autoCompleteTypes=array('BusinessCity','BusinessCountryRegion','BusinessFax','BusinessPhone','BusinessState','BusinessStreetAddress','BusinessUrl','BusinessZipCode','Cellular','Company','Department','Disabled','DisplayName','Email','FirstName','Gender','HomeCity','HomeCountryRegion','HomeFax','Homepage','HomePhone','HomeState','HomeStreetAddress','HomeZipCode','JobTitle','LastName','MiddleName','None','Notes','Office','Pager','Search');
+
+ /**
* @return string tag name of the textbox
*/
protected function getTagName()
@@ -48,7 +57,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
/**
* Adds attribute name-value pairs to renderer.
- * This overrides the parent implementation with additional textbox specific attributes.
+ * This method overrides the parent implementation with additional textbox specific attributes.
* @param THtmlWriter the writer used for the rendering purpose
*/
protected function addAttributesToRender($writer)
@@ -59,10 +68,12 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
$writer->addAttribute('name',$uid);
if(($textMode=$this->getTextMode())==='MultiLine')
{
- if(($rows=$this->getRows())>0)
- $writer->addAttribute('rows',$rows);
- if(($cols=$this->getColumns())>0)
- $writer->addAttribute('cols',$cols);
+ if(($rows=$this->getRows())<=0)
+ $rows=2;
+ if(($cols=$this->getColumns())<=0)
+ $cols=20;
+ $writer->addAttribute('rows',"$rows");
+ $writer->addAttribute('cols',"$cols");
if(!$this->getWrap())
$writer->addAttribute('wrap','off');
}
@@ -98,9 +109,9 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
$writer->addAttribute('type','password');
}
if(($cols=$this->getColumns())>0)
- $writer->addAttribute('size',$cols);
+ $writer->addAttribute('size',"$cols");
if(($maxLength=$this->getMaxLength())>0)
- $writer->addAttribute('maxlength',$maxLength);
+ $writer->addAttribute('maxlength',"$maxLength");
}
if($this->getReadOnly())
$writer->addAttribute('readonly','readonly');
@@ -108,30 +119,25 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
$writer->addAttribute('disabled','disabled');
if($this->getAutoPostBack() && $page->getClientSupportsJavaScript())
{
- $onchange='';
- $onkeypress='if (WebForm_TextBoxKeyHandler() == false) return false;';
- if($this->getHasAttributes())
+ $option=new TPostBackOptions();
+ if($this->getCausesValidation() && $page->getValidators($this->getValidationGroup())->getCount()>0)
{
- $attributes=$this->getAttributes();
- $onchange=$attributes->itemAt('onchange');
- if($onchange!=='')
- $onchange=rtrim($onchange,';').';';
- $attributes->remove('onchange');
- $onkeypress.=$attributes->itemAt('onkeypress');
- $attributes->remove('onkeypress');
+ $option->setPerformValidation(true);
+ $option->setValidationGroup($this->getValidationGroup());
}
+ $option->setAutoPostBack(true);
+ $onchange=$this->removeAttribute('onchange');
+ $onchange.=THttpUtility::trimJavaScriptString($onchange).$page->getClientScript()->getPostBackEventReference($this,'',$option,false);
+ $writer->addAttribute('onchange','javascript:'.$onchange);
- $option=new TPostBackOptions($this);
- if($this->getCausesValidation())
+ if($textMode!=='MultiLine')
{
- $option->PerformValidation=true;
- $option->ValidationGroup=$this->getValidationGroup();
+ // note, Prado.TextBox.handleReturnKey is defined in base.js,
+ // which is included when AutoPostBack is true for textbox.
+ $onkeypress='javascript:if(Prado.TextBox.handleReturnKey(event)==false) return false;';
+ $onkeypress.=THttpUtility::trimJavaScriptString($this->removeAttribute('onkeypress'));
+ $writer->addAttribute('onkeypress',$onkeypress);
}
- if($page->getForm())
- $option->AutoPostBack=true;
- $onchange.=$page->getClientScript()->getPostBackEventReference($option);
- $writer->addAttribute('onchange',$onchange);
- $writer->addAttribute('onkeypress',$onkeypress);
}
parent::addAttributesToRender($writer);
}
@@ -155,23 +161,6 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
return false;
}
- protected function onPreRender($param)
- {
- parent::onPreRender($param);
- if(($page=$this->getPage()) && $this->getEnabled(true))
- {
- // TODO
- //if($this->getTextMode()==='Password' || ($this->hasEventHandler('TextChanged') && $this->getVisible()))
- // $page->registerEnabledControl($this);
- if($this->getAutoPostBack())
- {
- $page->registerWebFormsScript();
- $page->registerPostBackScript();
- $page->registerFocusScript();
- }
- }
- }
-
/**
* Returns the value to be validated.
* This methid is required by IValidatable interface.
@@ -183,8 +172,8 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * This method is invoked when the value of the <b>Text</b> property changes on postback.
- * The method raises 'TextChanged' event.
+ * This method is invoked when the value of the {@link getText Text}
+ * property changes on postback. The method raises <b>TextChanged</b> event.
* If you override this method, be sure to call the parent implementation to ensure
* the invocation of the attached event handlers.
* @param TEventParameter event parameter to be passed to the event handlers
@@ -196,8 +185,9 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
/**
* Raises postdata changed event.
- * This method is required by IPostBackDataHandler interface.
- * It is invoked by the framework when <b>Text</b> property is changed on postback.
+ * This method is required by {@link IPostBackDataHandler} interface.
+ * It is invoked by the framework when {@link getText Text} property
+ * is changed on postback.
* This method is primarly used by framework developers.
*/
public function raisePostDataChangedEvent()
@@ -209,7 +199,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
if($this->getCausesValidation())
$page->validate($this->getValidationGroup());
}
- $this->onTextChanged(new TEventParameter);
+ $this->onTextChanged(null);
}
/**
@@ -243,13 +233,13 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
*/
public function setAutoCompleteType($value)
{
- $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,array('BusinessCity','BusinessCountryRegion','BusinessFax','BusinessPhone','BusinessState','BusinessStreetAddress','BusinessUrl','BusinessZipCode','Cellular','Company','Department','Disabled','DisplayName','Email','FirstName','Gender','HomeCity','HomeCountryRegion','HomeFax','Homepage','HomePhone','HomeState','HomeStreetAddress','HomeZipCode','JobTitle','LastName','MiddleName','None','Notes','Office','Pager','Search')),'None');
+ $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,self::$_autoCompleteTypes),'None');
}
/**
* @return boolean a value indicating whether an automatic postback to the server
* will occur whenever the user modifies the text in the TTextBox control and
- * then tabs out of the component.
+ * then tabs out of the component. Defaults to false.
*/
public function getAutoPostBack()
{
@@ -319,7 +309,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * @return boolean whether the textbox is read only, default is false
+ * @return boolean whether the textbox is read only, default is false.
*/
public function getReadOnly()
{
@@ -339,7 +329,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
*/
public function getRows()
{
- return $this->getViewState('Rows',4);
+ return $this->getViewState('Rows',0);
}
/**
@@ -348,7 +338,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
*/
public function setRows($value)
{
- $this->setViewState('Rows',TPropertyValue::ensureInteger($value),4);
+ $this->setViewState('Rows',TPropertyValue::ensureInteger($value),0);
}
/**
@@ -369,7 +359,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * @return string the behavior mode (SingleLine, MultiLine, or Password) of the TTextBox component.
+ * @return string the behavior mode (SingleLine, MultiLine, or Password) of the TTextBox component. Defaults to SingleLine.
*/
public function getTextMode()
{
@@ -403,7 +393,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable
}
/**
- * @return boolean whether the text content wraps within a multiline text box.
+ * @return boolean whether the text content wraps within a multiline text box. Defaults to true.
*/
public function getWrap()
{