mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Fixes #16629: ActiveField::inputOptions were not merged with options passed for radio and checkbox
This commit is contained in:
committed by
Alexander Makarov
parent
06227c7075
commit
8334ab3060
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.16 under development
|
2.0.16 under development
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
- Bug #16629: ActiveField::inputOptions were not merged with options passed for radio and checkbox (paweljankowiak06)
|
||||||
- Bug #16648: Html::strtolower() was corrupting UTF-8 strings (Kolyunya)
|
- Bug #16648: Html::strtolower() was corrupting UTF-8 strings (Kolyunya)
|
||||||
- Bug #13977: Skip validation if file input does not exist (RobinKamps, s1lver)
|
- Bug #13977: Skip validation if file input does not exist (RobinKamps, s1lver)
|
||||||
- Bug #16183: Fixed when `yii\helpers\BaseFileHelper` sometimes returned wrong value (samdark, SilverFire, OndrejVasicek)
|
- Bug #16183: Fixed when `yii\helpers\BaseFileHelper` sometimes returned wrong value (samdark, SilverFire, OndrejVasicek)
|
||||||
|
|||||||
@ -542,6 +542,8 @@ class ActiveField extends Component
|
|||||||
*/
|
*/
|
||||||
public function radio($options = [], $enclosedByLabel = true)
|
public function radio($options = [], $enclosedByLabel = true)
|
||||||
{
|
{
|
||||||
|
$options = array_merge($this->inputOptions, $options);
|
||||||
|
|
||||||
if ($enclosedByLabel) {
|
if ($enclosedByLabel) {
|
||||||
$this->parts['{input}'] = Html::activeRadio($this->model, $this->attribute, $options);
|
$this->parts['{input}'] = Html::activeRadio($this->model, $this->attribute, $options);
|
||||||
$this->parts['{label}'] = '';
|
$this->parts['{label}'] = '';
|
||||||
@ -594,6 +596,8 @@ class ActiveField extends Component
|
|||||||
*/
|
*/
|
||||||
public function checkbox($options = [], $enclosedByLabel = true)
|
public function checkbox($options = [], $enclosedByLabel = true)
|
||||||
{
|
{
|
||||||
|
$options = array_merge($this->inputOptions, $options);
|
||||||
|
|
||||||
if ($enclosedByLabel) {
|
if ($enclosedByLabel) {
|
||||||
$this->parts['{input}'] = Html::activeCheckbox($this->model, $this->attribute, $options);
|
$this->parts['{input}'] = Html::activeCheckbox($this->model, $this->attribute, $options);
|
||||||
$this->parts['{label}'] = '';
|
$this->parts['{label}'] = '';
|
||||||
|
|||||||
@ -249,7 +249,7 @@ EOT;
|
|||||||
|
|
||||||
public function testTabularInputErrors()
|
public function testTabularInputErrors()
|
||||||
{
|
{
|
||||||
$this->activeField->attribute = '[0]'.$this->attributeName;
|
$this->activeField->attribute = '[0]' . $this->attributeName;
|
||||||
$this->helperModel->addError($this->attributeName, 'Error Message');
|
$this->helperModel->addError($this->attributeName, 'Error Message');
|
||||||
|
|
||||||
$expectedValue = '<div class="form-group field-activefieldtestmodel-0-attributename has-error">';
|
$expectedValue = '<div class="form-group field-activefieldtestmodel-0-attributename has-error">';
|
||||||
@ -584,6 +584,78 @@ HTML;
|
|||||||
$this->assertEqualsWithoutLE($expectedValue, trim($actualValue));
|
$this->assertEqualsWithoutLE($expectedValue, trim($actualValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInputOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<input type="text" id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" data-id="3">';
|
||||||
|
$field = $this->activeField->input('text', ['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTextInputOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<input type="text" id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" data-id="3">';
|
||||||
|
$field = $this->activeField->textInput(['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHiddenInputOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<input type="hidden" id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" data-id="3">';
|
||||||
|
$field = $this->activeField->hiddenInput(['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPasswordInputOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<input type="password" id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" data-id="3">';
|
||||||
|
$field = $this->activeField->passwordInput(['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTextareaInputOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<textarea id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" data-id="3">';
|
||||||
|
$field = $this->activeField->textarea(['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRadioInputOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<input type="radio" id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" value="1" data-id="3">';
|
||||||
|
$field = $this->activeField->radio(['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCheckboxInputOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<input type="checkbox" id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" value="1" data-id="3">';
|
||||||
|
$field = $this->activeField->checkbox(['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDropdownListOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<select id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" data-id="3">';
|
||||||
|
$field = $this->activeField->dropDownList([0 => 'No', 1 => 'Yes'], ['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListboxOptionsAreMergedFromActiveField()
|
||||||
|
{
|
||||||
|
$this->removeLabelHintAndError();
|
||||||
|
$expectedValue = '<select id="activefieldtestmodel-attributename" class="form-control" name="ActiveFieldTestModel[attributeName]" size="4" data-id="3">';
|
||||||
|
$field = $this->activeField->listBox([0 => 'No', 1 => 'Yes'], ['data-id' => 3])->render();
|
||||||
|
self::assertContains($expectedValue, $field);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper methods.
|
* Helper methods.
|
||||||
*/
|
*/
|
||||||
@ -597,6 +669,11 @@ HTML;
|
|||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function removeLabelHintAndError()
|
||||||
|
{
|
||||||
|
$this->activeField->label(false)->error(false)->hint(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ActiveFieldTestModel extends DynamicModel
|
class ActiveFieldTestModel extends DynamicModel
|
||||||
|
|||||||
Reference in New Issue
Block a user