Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ActiveField class #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions src/ActiveField.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ public function radio($options = [], $enclosedByLabel = false)
*/
public function checkboxList($items, $options = [])
{
if (isset($options['inline'])) {
$this->inline(ArrayHelper::remove($options, 'inline'));
}

if (!isset($options['item'])) {
$this->template = str_replace("\n{error}", '', $this->template);
$itemOptions = $options['itemOptions'] ?? [];
Expand All @@ -363,6 +367,8 @@ public function checkboxList($items, $options = [])
$wrapperOptions = ArrayHelper::remove($options, 'wrapperOptions', ['class' => ['widget' => 'form-check']]);
if ($this->inline) {
Html::addCssClass($wrapperOptions, ['inline' => 'form-check-inline']);
} else {
Html::removeCssClass($wrapperOptions, 'form-check-inline');
}

$html = Html::beginTag('div', $wrapperOptions) . "\n" .
Expand All @@ -376,16 +382,18 @@ public function checkboxList($items, $options = [])
};
}

parent::checkboxList($items, $options);

return $this;
return parent::checkboxList($items, $options);
}

/**
* {@inheritdoc}
*/
public function radioList($items, $options = [])
{
if (isset($options['inline'])) {
$this->inline(ArrayHelper::remove($options, 'inline'));
}

if (!isset($options['item'])) {
$this->template = str_replace("\n{error}", '', $this->template);
$itemOptions = $options['itemOptions'] ?? [];
Expand All @@ -405,6 +413,8 @@ public function radioList($items, $options = [])
$wrapperOptions = ArrayHelper::remove($options, 'wrapperOptions', ['class' => ['widget' => 'form-check']]);
if ($this->inline) {
Html::addCssClass($wrapperOptions, ['inline' => 'form-check-inline']);
} else {
Html::removeCssClass($wrapperOptions, 'form-check-inline');
}

$html = Html::beginTag('div', $wrapperOptions) . "\n" .
Expand All @@ -418,9 +428,7 @@ public function radioList($items, $options = [])
};
}

parent::radioList($items, $options);

return $this;
return parent::radioList($items, $options);
}

/**
Expand Down Expand Up @@ -487,9 +495,24 @@ public function label($label = null, $options = [])
}

/**
* @param bool $value whether to render a inline list
* @return $this the field object itself
* {@inheritdoc}
*/
public function error($options = [])
{
if ($options === false) {
$this->enableError = false;

return $this;
}

return parent::error($options);
}

/**
* Make sure you call this method before [[checkboxList()]] or [[radioList()]] to have any effect.
*
* @param bool $value whether to render a inline list
* @return $this
*/
public function inline($value = true): self
{
Expand Down