Skip to content

Commit e04a4f2

Browse files
committed
remove .input-field from checkbox/radio container, fixes #30, fixes #36
1 parent 44d75b5 commit e04a4f2

File tree

2 files changed

+4
-100
lines changed

2 files changed

+4
-100
lines changed

src/lib/Html.php

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -133,80 +133,4 @@ private static function normalizeMaxLength($model, $attribute, &$options)
133133
}
134134
}
135135
}
136-
137-
/**
138-
* Generates a radio button tag together with a label for the given model attribute.
139-
* This method will generate the "checked" tag attribute according to the model attribute value.
140-
* @param Model $model the model object
141-
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
142-
* about attribute expression.
143-
* @param array $options the tag options in terms of name-value pairs.
144-
* See [[booleanInput()]] for details about accepted attributes.
145-
*
146-
* @return string the generated radio button tag
147-
*/
148-
public static function activeRadio($model, $attribute, $options = [])
149-
{
150-
return static::activeBooleanInput('radio', $model, $attribute, $options);
151-
}
152-
153-
/**
154-
* Generates a checkbox tag together with a label for the given model attribute.
155-
* This method will generate the "checked" tag attribute according to the model attribute value.
156-
* @param Model $model the model object
157-
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
158-
* about attribute expression.
159-
* @param array $options the tag options in terms of name-value pairs.
160-
* See [[booleanInput()]] for details about accepted attributes.
161-
*
162-
* @return string the generated checkbox tag
163-
*/
164-
public static function activeCheckbox($model, $attribute, $options = [])
165-
{
166-
return static::activeBooleanInput('checkbox', $model, $attribute, $options);
167-
}
168-
169-
/**
170-
* Generates a boolean input
171-
* This method is mainly called by [[activeCheckbox()]] and [[activeRadio()]].
172-
* @param string $type the input type. This can be either `radio` or `checkbox`.
173-
* @param Model $model the model object
174-
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
175-
* about attribute expression.
176-
* @param array $options the tag options in terms of name-value pairs.
177-
* See [[booleanInput()]] for details about accepted attributes.
178-
* @return string the generated input element
179-
* @since 2.0.9
180-
*/
181-
protected static function activeBooleanInput($type, $model, $attribute, $options = [])
182-
{
183-
$name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
184-
$value = static::getAttributeValue($model, $attribute);
185-
186-
if (!array_key_exists('value', $options)) {
187-
$options['value'] = '1';
188-
}
189-
if (!array_key_exists('uncheck', $options)) {
190-
$options['uncheck'] = '0';
191-
} elseif ($options['uncheck'] === false) {
192-
unset($options['uncheck']);
193-
}
194-
if (!array_key_exists('label', $options)) {
195-
$options['label'] = static::encode($model->getAttributeLabel(static::getAttributeName($attribute)));
196-
} elseif ($options['label'] === false) {
197-
unset($options['label']);
198-
}
199-
200-
if (isset($options['label'])) {
201-
$options['label'] = '<span>' . $options['label'] . '</span>';
202-
}
203-
204-
$checked = "$value" === "{$options['value']}";
205-
206-
if (!array_key_exists('id', $options)) {
207-
$options['id'] = static::getInputId($model, $attribute);
208-
}
209-
210-
return static::$type($name, $checked, $options);
211-
}
212136
}

src/widgets/form/ActiveField.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,12 @@ public function icon()
249249
* Materialize standard to not wrap the checkboxes in labels.
250250
* @return $this
251251
*/
252-
public function checkbox($options = [], $enclosedByLabel = true)
252+
public function checkbox($options = [], $enclosedByLabel = false)
253253
{
254254
Html::addCssClass($this->options, ['class' => 'checkbox']);
255255
Html::removeCssClass($this->options, 'input-field');
256256

257-
$this->parts['{input}'] = Html::activeCheckbox($this->model, $this->attribute, $options);
258-
$this->parts['{label}'] = '';
259-
260-
if ($this->form->validationStateOn === ActiveForm::VALIDATION_STATE_ON_INPUT) {
261-
$this->addErrorClassIfNeeded($options);
262-
}
263-
264-
$this->addAriaAttributes($options);
265-
$this->adjustLabelFor($options);
266-
267-
return $this;
257+
return parent::checkbox($options, $enclosedByLabel);
268258
}
269259

270260
/**
@@ -296,22 +286,12 @@ public function dropDownList($items, $options = [])
296286
* Materialize standard to not wrap the checkboxes in labels.
297287
* @return $this
298288
*/
299-
public function radio($options = [], $enclosedByLabel = true)
289+
public function radio($options = [], $enclosedByLabel = false)
300290
{
301291
Html::addCssClass($this->options, ['class' => 'radio']);
302292
Html::removeCssClass($this->options, 'input-field');
303293

304-
$this->parts['{input}'] = Html::activeRadio($this->model, $this->attribute, $options);
305-
$this->parts['{label}'] = '';
306-
307-
if ($this->form->validationStateOn === ActiveForm::VALIDATION_STATE_ON_INPUT) {
308-
$this->addErrorClassIfNeeded($options);
309-
}
310-
311-
$this->addAriaAttributes($options);
312-
$this->adjustLabelFor($options);
313-
314-
return $this;
294+
return parent::radio($options, $enclosedByLabel);
315295
}
316296

317297
/**

0 commit comments

Comments
 (0)