Differenze tra le versioni di "SfWidgetFormReadOnlyInput"
Jump to navigation
Jump to search
imported>Giorgio |
imported>Giorgio |
||
| (3 versioni intermedie di uno stesso utente non sono mostrate) | |||
| Riga 3: | Riga 3: | ||
Così ho creato questo. | Così ho creato questo. | ||
| − | Quando il campo | + | Quando il campo è readonly crea un input hidden e scrive il valore in uno span formattato con i suoi attributi. |
| + | |||
| + | <pre> <span >Un testo</span><hidden name="quest[name]" value="Un testo" id="quest_name" /></pre> | ||
<pre> | <pre> | ||
| Riga 23: | Riga 25: | ||
public function render($name, $value = null, $attributes = array(), $errors = array()) | public function render($name, $value = null, $attributes = array(), $errors = array()) | ||
{ | { | ||
| − | if ($ | + | if (isset($attributes['readonly'])) |
{ | { | ||
$attributes_reduced = $attributes; | $attributes_reduced = $attributes; | ||
| − | unset($ | + | unset($this->attributes['readonly'],$attributes_reduced['name'],$attributes_reduced['readonly']); |
return "<span ".$this->attributesToHtml($attributes_reduced).">".sprintf($this->getOption('format'),($value?$value:($this->getOption('default_value'))))."</span>".$this->renderTag('hidden', array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value), $attributes)); | return "<span ".$this->attributesToHtml($attributes_reduced).">".sprintf($this->getOption('format'),($value?$value:($this->getOption('default_value'))))."</span>".$this->renderTag('hidden', array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value), $attributes)); | ||
} else { | } else { | ||
Versione attuale delle 13:38, 4 lug 2010
Avevo bisogno di un widget in symfony che mi mettesse del testo fisso quando il campo è readonly.
Così ho creato questo.
Quando il campo è readonly crea un input hidden e scrive il valore in uno span formattato con i suoi attributi.
<span >Un testo</span><hidden name="quest[name]" value="Un testo" id="quest_name" />
<?php
/**
* sfWidgetFormReadOnlyInput is an input widget with read only option that render a fix text forms
*
* @author Giorgio Borgonovo borgonovo [at] tavernadelleidee.it
*/
class sfWidgetFormReadOnlyInput extends sfWidgetForm
{
public function configure($options = array(), $attributes = array())
{
$this->addOption('format',"%s");
$this->addOption('default_value'," ");
parent::configure($options = array(), $attributes = array());
}
public function render($name, $value = null, $attributes = array(), $errors = array())
{
if (isset($attributes['readonly']))
{
$attributes_reduced = $attributes;
unset($this->attributes['readonly'],$attributes_reduced['name'],$attributes_reduced['readonly']);
return "<span ".$this->attributesToHtml($attributes_reduced).">".sprintf($this->getOption('format'),($value?$value:($this->getOption('default_value'))))."</span>".$this->renderTag('hidden', array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value), $attributes));
} else {
return $this->renderTag('input', array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value), $attributes));
}
}
}
?>