From 4a4dd411abb23243d46a43e92deb4d22f2d34b17 Mon Sep 17 00:00:00 2001 From: Jens Klaer Date: Tue, 18 Aug 2015 15:17:42 +0200 Subject: TButton now supports using input or button for the tag name the tag name used to render the TButton can now be changed by setting the property ButtonTag (defaults to input) using an enumerable class. this is especially useful when styling buttons using bootstrap along with prado. --- framework/Web/UI/WebControls/TButton.php | 45 +++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php index f24985e6..d9383d1e 100644 --- a/framework/Web/UI/WebControls/TButton.php +++ b/framework/Web/UI/WebControls/TButton.php @@ -52,7 +52,23 @@ class TButton extends TWebControl implements IPostBackEventHandler, IButtonContr */ protected function getTagName() { - return 'input'; + return strtolower($this->getButtonTag()); + } + + /** + * @return TButtonTag the tag name of the button. Defaults to TButtonType::Input. + */ + public function getButtonTag() + { + return $this->getViewState('ButtonTag',TButtonTag::Input); + } + + /** + * @param TButtonTag the tag name of the button. + */ + public function setButtonTag($value) + { + $this->setViewState('ButtonTag',TPropertyValue::ensureEnum($value,'TButtonTag'),TButtonTag::Input); } /** @@ -83,7 +99,10 @@ class TButton extends TWebControl implements IPostBackEventHandler, IButtonContr $writer->addAttribute('type',strtolower($this->getButtonType())); if(($uniqueID=$this->getUniqueID())!=='') $writer->addAttribute('name',$uniqueID); - $writer->addAttribute('value',$this->getText()); + if($this->getButtonTag()===TButtonTag::Button) + $this->addParsedObject($this->getText()); + else + $writer->addAttribute('value',$this->getText()); if($this->getEnabled(true)) { if($this->getEnableClientScript() && $this->needPostBackScript()) @@ -171,11 +190,14 @@ class TButton extends TWebControl implements IPostBackEventHandler, IButtonContr /** * Renders the body content enclosed between the control tag. - * This overrides the parent implementation with nothing to be rendered. + * This overrides the parent implementation with nothing to be rendered for input tags, + * button tags are rendered normally. * @param THtmlWriter the writer used for the rendering purpose */ public function renderContents($writer) { + if($this->getButtonTag()===TButtonTag::Button) + parent::renderContents($writer); } /** @@ -363,3 +385,20 @@ class TButtonType extends TEnumerable const Button='Button'; } +/** + * TButtonTag class. + * TButtonTag defines the enumerable type for the possible tag names that a {@link TButton} can use for rendering. + * + * The following enumerable values are defined: + * - Input: an input tag is rendered + * - Button: a button tag is rendered + * + * @author LANDWEHR Computer und Software GmbH + * @package System.Web.UI.WebControls + */ +class TButtonTag extends TEnumerable +{ + const Input='Input'; + const Button='Button'; +} + -- cgit v1.2.3