Skip to content

Commit

Permalink
remove .input-field from checkbox/radio container, fixes #30, fixes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
MacGyer committed Mar 25, 2018
1 parent 44d75b5 commit e04a4f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 100 deletions.
76 changes: 0 additions & 76 deletions src/lib/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,80 +133,4 @@ private static function normalizeMaxLength($model, $attribute, &$options)
}
}
}

/**
* Generates a radio button tag together with a label for the given model attribute.
* This method will generate the "checked" tag attribute according to the model attribute value.
* @param Model $model the model object
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param array $options the tag options in terms of name-value pairs.
* See [[booleanInput()]] for details about accepted attributes.
*
* @return string the generated radio button tag
*/
public static function activeRadio($model, $attribute, $options = [])
{
return static::activeBooleanInput('radio', $model, $attribute, $options);
}

/**
* Generates a checkbox tag together with a label for the given model attribute.
* This method will generate the "checked" tag attribute according to the model attribute value.
* @param Model $model the model object
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param array $options the tag options in terms of name-value pairs.
* See [[booleanInput()]] for details about accepted attributes.
*
* @return string the generated checkbox tag
*/
public static function activeCheckbox($model, $attribute, $options = [])
{
return static::activeBooleanInput('checkbox', $model, $attribute, $options);
}

/**
* Generates a boolean input
* This method is mainly called by [[activeCheckbox()]] and [[activeRadio()]].
* @param string $type the input type. This can be either `radio` or `checkbox`.
* @param Model $model the model object
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param array $options the tag options in terms of name-value pairs.
* See [[booleanInput()]] for details about accepted attributes.
* @return string the generated input element
* @since 2.0.9
*/
protected static function activeBooleanInput($type, $model, $attribute, $options = [])
{
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
$value = static::getAttributeValue($model, $attribute);

if (!array_key_exists('value', $options)) {
$options['value'] = '1';
}
if (!array_key_exists('uncheck', $options)) {
$options['uncheck'] = '0';
} elseif ($options['uncheck'] === false) {
unset($options['uncheck']);
}
if (!array_key_exists('label', $options)) {
$options['label'] = static::encode($model->getAttributeLabel(static::getAttributeName($attribute)));
} elseif ($options['label'] === false) {
unset($options['label']);
}

if (isset($options['label'])) {
$options['label'] = '<span>' . $options['label'] . '</span>';
}

$checked = "$value" === "{$options['value']}";

if (!array_key_exists('id', $options)) {
$options['id'] = static::getInputId($model, $attribute);
}

return static::$type($name, $checked, $options);
}
}
28 changes: 4 additions & 24 deletions src/widgets/form/ActiveField.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,12 @@ public function icon()
* Materialize standard to not wrap the checkboxes in labels.
* @return $this
*/
public function checkbox($options = [], $enclosedByLabel = true)
public function checkbox($options = [], $enclosedByLabel = false)
{
Html::addCssClass($this->options, ['class' => 'checkbox']);
Html::removeCssClass($this->options, 'input-field');

$this->parts['{input}'] = Html::activeCheckbox($this->model, $this->attribute, $options);
$this->parts['{label}'] = '';

if ($this->form->validationStateOn === ActiveForm::VALIDATION_STATE_ON_INPUT) {
$this->addErrorClassIfNeeded($options);
}

$this->addAriaAttributes($options);
$this->adjustLabelFor($options);

return $this;
return parent::checkbox($options, $enclosedByLabel);
}

/**
Expand Down Expand Up @@ -296,22 +286,12 @@ public function dropDownList($items, $options = [])
* Materialize standard to not wrap the checkboxes in labels.
* @return $this
*/
public function radio($options = [], $enclosedByLabel = true)
public function radio($options = [], $enclosedByLabel = false)
{
Html::addCssClass($this->options, ['class' => 'radio']);
Html::removeCssClass($this->options, 'input-field');

$this->parts['{input}'] = Html::activeRadio($this->model, $this->attribute, $options);
$this->parts['{label}'] = '';

if ($this->form->validationStateOn === ActiveForm::VALIDATION_STATE_ON_INPUT) {
$this->addErrorClassIfNeeded($options);
}

$this->addAriaAttributes($options);
$this->adjustLabelFor($options);

return $this;
return parent::radio($options, $enclosedByLabel);
}

/**
Expand Down

0 comments on commit e04a4f2

Please sign in to comment.