-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d88c1b
commit 1337909
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the symfony package. | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* sfWidgetFormInputRead represents an HTML text hidden input tag with readonly text input tag containing text to read. | ||
* | ||
* @package symfony | ||
* @subpackage widget | ||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* @version SVN: $Id$ | ||
*/ | ||
class sfWidgetFormInputRead extends sfWidgetFormInput | ||
{ | ||
/** | ||
* Configures the current widget. | ||
* | ||
* @param array $options An array of options | ||
* @param array $attributes An array of default HTML attributes | ||
* | ||
* @see sfWidgetForm | ||
*/ | ||
protected function configure($options = array(), $attributes = array()) | ||
{ | ||
parent::configure($options, $attributes); | ||
|
||
$this->addOption('text'); | ||
$this->setOption('type', 'hidden'); | ||
} | ||
|
||
/** | ||
* Render the current widget | ||
* | ||
* @param string $name The element name | ||
* @param string $value The this widget is checked if value is not null | ||
* @param array $attributes An array of HTML attributes to be merged with the default HTML attributes | ||
* @param array $errors An array of errors for the field | ||
* | ||
* @return string An HTML tag string | ||
* | ||
* @see sfWidgetForm | ||
*/ | ||
public function render($name, $value = null, $attributes = array(), $errors = array()) | ||
{ | ||
$attributes = array_merge($this->attributes, $attributes); | ||
$this->attributes = array(); | ||
|
||
$tag = parent::render($name, $value, array(), $errors); | ||
|
||
$style = 'border: 0;'; | ||
if (isset($attributes['style'])) | ||
{ | ||
$style .= ' '.$attributes['style']; | ||
unset($attributes['style']); | ||
} | ||
|
||
return $tag.$this->renderTag('input', array_merge(array( | ||
'type' => 'text', | ||
'value' => $this->getOption('text', $value), | ||
'readonly' => 'readonly', | ||
'style' => $style, | ||
), $attributes)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the symfony package. | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); | ||
|
||
$t = new lime_test(5); | ||
|
||
$w = new sfWidgetFormInputRead(); | ||
|
||
// ->render() | ||
$t->diag('->render()'); | ||
$t->is($w->render('foo'), '<input type="hidden" name="foo" id="foo" /><input type="text" readonly="readonly" style="border: 0;" />', '->render() renders the widget as HTML'); | ||
$t->is($w->render('foo', 'bar'), '<input type="hidden" name="foo" value="bar" id="foo" /><input type="text" value="bar" readonly="readonly" style="border: 0;" />', '->render() can take a value for the input'); | ||
$t->is($w->render('foo', '', array('class' => 'foobar', 'style' => 'width: 500px;')), '<input type="hidden" name="foo" value="" id="foo" /><input type="text" value="" readonly="readonly" style="border: 0; width: 500px;" class="foobar" />', '->render() can take HTML attributes as its third argument'); | ||
|
||
$w = new sfWidgetFormInputRead(array('text' => 'Read text')); | ||
$t->is($w->render('foo', 'bar'), '<input type="hidden" name="foo" value="bar" id="foo" /><input type="text" value="Read text" readonly="readonly" style="border: 0;" />', '->render() can take a value for the input and another value for read input'); | ||
|
||
$w = new sfWidgetFormInputRead(array(), array('class' => 'foobar', 'style' => 'width: 500px;')); | ||
$t->is($w->render('foo'), '<input type="hidden" name="foo" id="foo" /><input type="text" readonly="readonly" style="border: 0; width: 500px;" class="foobar" />', '__construct() can take default HTML attributes'); | ||
$t->is($w->render('foo', null, array('class' => 'barfoo')), '<input type="hidden" name="foo" id="foo" /><input type="text" readonly="readonly" style="border: 0;" class="barfoo" />', '->render() can override default attributes'); |
1337909
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess a "readonly" option in sfWidgetFormInput would have been enough. This way you can make read-only any radio/checkbox/textarea ...
1337909
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The widget allow to set a different value for visible input, with default custom style.
I don't know if it can be usefull for many people.