Browse Source

Simplified button signature.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
11c14a20e9
  1. 2
      apps/advanced/backend/views/site/login.php
  2. 2
      apps/advanced/frontend/views/site/contact.php
  3. 2
      apps/advanced/frontend/views/site/login.php
  4. 2
      apps/basic/views/site/contact.php
  5. 2
      apps/basic/views/site/login.php
  6. 45
      framework/yii/helpers/base/Html.php
  7. 16
      tests/unit/framework/helpers/HtmlTest.php

2
apps/advanced/backend/views/site/login.php

@ -22,6 +22,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $form->field('password')->passwordInput(); ?> <?php echo $form->field('password')->passwordInput(); ?>
<?php echo $form->field('rememberMe')->checkbox(); ?> <?php echo $form->field('rememberMe')->checkbox(); ?>
<div class="form-actions"> <div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?> <?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

2
apps/advanced/frontend/views/site/contact.php

@ -36,6 +36,6 @@ $this->params['breadcrumbs'][] = $this->title;
'options' => array('class' => 'input-medium'), 'options' => array('class' => 'input-medium'),
)); ?> )); ?>
<div class="form-actions"> <div class="form-actions">
<?php echo Html::submitButton('Submit', null, null, array('class' => 'btn btn-primary')); ?> <?php echo Html::submitButton('Submit', array('class' => 'btn btn-primary')); ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

2
apps/advanced/frontend/views/site/login.php

@ -22,6 +22,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $form->field('password')->passwordInput(); ?> <?php echo $form->field('password')->passwordInput(); ?>
<?php echo $form->field('rememberMe')->checkbox(); ?> <?php echo $form->field('rememberMe')->checkbox(); ?>
<div class="form-actions"> <div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?> <?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

2
apps/basic/views/site/contact.php

@ -36,6 +36,6 @@ $this->params['breadcrumbs'][] = $this->title;
'options' => array('class' => 'input-medium'), 'options' => array('class' => 'input-medium'),
)); ?> )); ?>
<div class="form-actions"> <div class="form-actions">
<?php echo Html::submitButton('Submit', null, null, array('class' => 'btn btn-primary')); ?> <?php echo Html::submitButton('Submit', array('class' => 'btn btn-primary')); ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

2
apps/basic/views/site/login.php

@ -22,6 +22,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $form->field('password')->passwordInput(); ?> <?php echo $form->field('password')->passwordInput(); ?>
<?php echo $form->field('rememberMe')->checkbox(); ?> <?php echo $form->field('rememberMe')->checkbox(); ?>
<div class="form-actions"> <div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?> <?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

45
framework/yii/helpers/base/Html.php

@ -421,18 +421,14 @@ class Html
* @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded. * @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded.
* Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, * Therefore you can pass in HTML code such as an image tag. If this is is coming from end users,
* you should consider [[encode()]] it to prevent XSS attacks. * you should consider [[encode()]] it to prevent XSS attacks.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as * @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered. * If a value is null, the corresponding attribute will not be rendered.
* If the options does not contain "type", a "type" attribute with value "button" will be rendered. * If the options does not contain "type", a "type" attribute with value "button" will be rendered.
* @return string the generated button tag * @return string the generated button tag
*/ */
public static function button($content = 'Button', $name = null, $value = null, $options = array()) public static function button($content = 'Button', $options = array())
{ {
$options['name'] = $name;
$options['value'] = $value;
if (!isset($options['type'])) { if (!isset($options['type'])) {
$options['type'] = 'button'; $options['type'] = 'button';
} }
@ -444,17 +440,15 @@ class Html
* @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded. * @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded.
* Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, * Therefore you can pass in HTML code such as an image tag. If this is is coming from end users,
* you should consider [[encode()]] it to prevent XSS attacks. * you should consider [[encode()]] it to prevent XSS attacks.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as * @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered. * If a value is null, the corresponding attribute will not be rendered.
* @return string the generated submit button tag * @return string the generated submit button tag
*/ */
public static function submitButton($content = 'Submit', $name = null, $value = null, $options = array()) public static function submitButton($content = 'Submit', $options = array())
{ {
$options['type'] = 'submit'; $options['type'] = 'submit';
return static::button($content, $name, $value, $options); return static::button($content, $options);
} }
/** /**
@ -462,17 +456,15 @@ class Html
* @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded. * @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded.
* Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, * Therefore you can pass in HTML code such as an image tag. If this is is coming from end users,
* you should consider [[encode()]] it to prevent XSS attacks. * you should consider [[encode()]] it to prevent XSS attacks.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as * @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered. * If a value is null, the corresponding attribute will not be rendered.
* @return string the generated reset button tag * @return string the generated reset button tag
*/ */
public static function resetButton($content = 'Reset', $name = null, $value = null, $options = array()) public static function resetButton($content = 'Reset', $options = array())
{ {
$options['type'] = 'reset'; $options['type'] = 'reset';
return static::button($content, $name, $value, $options); return static::button($content, $options);
} }
/** /**
@ -495,43 +487,46 @@ class Html
/** /**
* Generates an input button. * Generates an input button.
* @param string $name the name attribute. * @param string $label the value attribute. If it is null, the value attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as * @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered. * If a value is null, the corresponding attribute will not be rendered.
* @return string the generated button tag * @return string the generated button tag
*/ */
public static function buttonInput($name, $value = 'Button', $options = array()) public static function buttonInput($label = 'Button', $options = array())
{ {
return static::input('button', $name, $value, $options); $options['type'] = 'button';
$options['value'] = $label;
return static::tag('input', null, $options);
} }
/** /**
* Generates a submit input button. * Generates a submit input button.
* @param string $name the name attribute. If it is null, the name attribute will not be generated. * @param string $label the value attribute. If it is null, the value attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as * @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. * the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered. * If a value is null, the corresponding attribute will not be rendered.
* @return string the generated button tag * @return string the generated button tag
*/ */
public static function submitInput($name = null, $value = 'Submit', $options = array()) public static function submitInput($label = 'Submit', $options = array())
{ {
return static::input('submit', $name, $value, $options); $options['type'] = 'submit';
$options['value'] = $label;
return static::tag('input', null, $options);
} }
/** /**
* Generates a reset input button. * Generates a reset input button.
* @param string $name the name attribute. If it is null, the name attribute will not be generated. * @param string $label the value attribute. If it is null, the value attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the attributes of the button tag. The values will be HTML-encoded using [[encode()]]. * @param array $options the attributes of the button tag. The values will be HTML-encoded using [[encode()]].
* Attributes whose value is null will be ignored and not put in the tag returned. * Attributes whose value is null will be ignored and not put in the tag returned.
* @return string the generated button tag * @return string the generated button tag
*/ */
public static function resetInput($name = null, $value = 'Reset', $options = array()) public static function resetInput($label = 'Reset', $options = array())
{ {
return static::input('reset', $name, $value, $options); $options['type'] = 'reset';
$options['value'] = $label;
return static::tag('input', null, $options);
} }
/** /**

16
tests/unit/framework/helpers/HtmlTest.php

@ -154,20 +154,20 @@ class HtmlTest extends TestCase
public function testButton() public function testButton()
{ {
$this->assertEquals('<button type="button">Button</button>', Html::button()); $this->assertEquals('<button type="button">Button</button>', Html::button());
$this->assertEquals('<button type="button" name="test" value="value">content<></button>', Html::button('content<>', 'test', 'value')); $this->assertEquals('<button type="button" name="test" value="value">content<></button>', Html::button('content<>', array('name' => 'test', 'value' => 'value')));
$this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::button('content<>', 'test', 'value', array('type' => 'submit', 'class' => "t"))); $this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::button('content<>', array('type' => 'submit', 'name' => 'test', 'value' => 'value', 'class' => "t")));
} }
public function testSubmitButton() public function testSubmitButton()
{ {
$this->assertEquals('<button type="submit">Submit</button>', Html::submitButton()); $this->assertEquals('<button type="submit">Submit</button>', Html::submitButton());
$this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::submitButton('content<>', 'test', 'value', array('class' => 't'))); $this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::submitButton('content<>', array('name' => 'test', 'value' => 'value', 'class' => 't')));
} }
public function testResetButton() public function testResetButton()
{ {
$this->assertEquals('<button type="reset">Reset</button>', Html::resetButton()); $this->assertEquals('<button type="reset">Reset</button>', Html::resetButton());
$this->assertEquals('<button type="reset" class="t" name="test" value="value">content<></button>', Html::resetButton('content<>', 'test', 'value', array('class' => 't'))); $this->assertEquals('<button type="reset" class="t" name="test" value="value">content<></button>', Html::resetButton('content<>', array('name' => 'test', 'value' => 'value', 'class' => 't')));
} }
public function testInput() public function testInput()
@ -178,20 +178,20 @@ class HtmlTest extends TestCase
public function testButtonInput() public function testButtonInput()
{ {
$this->assertEquals('<input type="button" name="test" value="Button" />', Html::buttonInput('test')); $this->assertEquals('<input type="button" value="Button" />', Html::buttonInput());
$this->assertEquals('<input type="button" class="a" name="test" value="text" />', Html::buttonInput('test', 'text', array('class' => 'a'))); $this->assertEquals('<input type="button" class="a" name="test" value="text" />', Html::buttonInput('text', array('name' => 'test', 'class' => 'a')));
} }
public function testSubmitInput() public function testSubmitInput()
{ {
$this->assertEquals('<input type="submit" value="Submit" />', Html::submitInput()); $this->assertEquals('<input type="submit" value="Submit" />', Html::submitInput());
$this->assertEquals('<input type="submit" class="a" name="test" value="text" />', Html::submitInput('test', 'text', array('class' => 'a'))); $this->assertEquals('<input type="submit" class="a" name="test" value="text" />', Html::submitInput('text', array('name' => 'test', 'class' => 'a')));
} }
public function testResetInput() public function testResetInput()
{ {
$this->assertEquals('<input type="reset" value="Reset" />', Html::resetInput()); $this->assertEquals('<input type="reset" value="Reset" />', Html::resetInput());
$this->assertEquals('<input type="reset" class="a" name="test" value="text" />', Html::resetInput('test', 'text', array('class' => 'a'))); $this->assertEquals('<input type="reset" class="a" name="test" value="text" />', Html::resetInput('text', array('name' => 'test', 'class' => 'a')));
} }
public function testTextInput() public function testTextInput()

Loading…
Cancel
Save