Skip to content

Instantly share code, notes, and snippets.

@jkuchar
Created February 24, 2013 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkuchar/5025394 to your computer and use it in GitHub Desktop.
Save jkuchar/5025394 to your computer and use it in GitHub Desktop.
Graphical submit button for Nette forms. Allows you to put HTML content inside button.
class AdvancedSubmitButton extends SubmitButton {
var $icon = null;
var $showCaption = true;
/**
* @param string caption
* @param string icon url
*/
public function __construct($caption = NULL,$icon=NULL)
{
parent::__construct($caption);
if($icon) {
$this->iconPrototype->src = $icon;
}
$this->control->setName("button")->type = 'submit';
//$this->control->class[] = "button";
$this->control->class[] = "submit";
}
public function getIconPrototype() {
if(!$this->icon) {
$this->icon = Html::el("img");
}
return $this->icon;
}
function hideCaption(){
$this->showCaption = false;
return $this;
}
public function getControl($caption = NULL){
$control = parent::getControl($caption);
$control->setText(""); // Delete content
if($this->icon) {
$control->class[] = "hasIcon";
$this->icon->alt = $this->caption;
$control->add($this->icon);
}
if($this->showCaption) {
$control->class[] = "hasCaption";
$control->add(Html::el("span class=caption")->setHtml($this->caption));
}
// CSS classes:
if($this->icon and !$this->showCaption) {
$control->class[] = "hasIconAndNoCaption";
}elseif(!$this->icon and $this->showCaption) {
$control->class[] = "hasCaptionAndNoIcon";
}elseif($this->icon and $this->showCaption){
$control->class[] = "hasCaptionAndIcon";
}
return $control;
}
}
class BaseForm extends AppForm {
/**
* Adds button used to submit form.
* @param string control name
* @param string caption
* @return AdvancedSubmitButton
*/
public function addAdvSubmit($name, $caption, $icon = null)
{
return $this[$name] = new AdvancedSubmitButton($caption, $icon);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment