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

Support for custom switch #287

Open
2 tasks done
ashleybuckle opened this issue Nov 8, 2019 · 0 comments
Open
2 tasks done

Support for custom switch #287

ashleybuckle opened this issue Nov 8, 2019 · 0 comments

Comments

@ashleybuckle
Copy link

ashleybuckle commented Nov 8, 2019

This is a (multiple allowed):

  • enhancement

  • feature-discussion (RFC)

  • BootstrapUI Version: develop

  • Bootstrap Framework Version: 4.1.3

Not sure if I'm missing something, but I don't see support for custom-switch control without passing new templates in the control() function. I was wondering if you could add 'switch' to $options and make minor code adjustments.

I've added the following templates:

'customSwitchContainer' => '<div class="form-group custom-control custom-switch {{type}}{{required}}">{{content}}{{help}}</div>',
'customSwitchContainerError' => '<div class="form-group custom-control custom-switch {{type}}{{required}} is-invalid">{{content}}{{error}}{{help}}</div>',
'customSwitchInlineContainer' => '<div class="form-group custom-control custom-switch custom-control-inline {{type}}{{required}}">{{content}}</div>',
'customSwitchInlineContainerError' => '<div class="form-group custom-control custom-switch custom-control-inline {{type}}{{required}} is-invalid">{{content}}</div>',
'customSwitchWrapper' => '<div class="custom-control custom-switch">{{label}}</div>',
'customSwitchInlineWrapper' => '<div class="custom-control custom-switch custom-control-inline">{{label}}</div>',

'customSwitchFormGroup' => '<div class="%s"><div class="custom-control custom-switch">{{input}}{{label}}</div>{{error}}{{help}}</div>',

Code adjustment in the control() function:

if (empty($options['switch'])) {
  if ($this->_align === 'horizontal') {
      $options['templates']['checkboxFormGroup'] = $this->templater()->get('customCheckboxFormGroup');
  } else {
      $options['templates']['checkboxContainer'] = $this->templater()->get('customCheckboxContainer');
      $options['templates']['checkboxContainerError'] = $this->templater()->get('customCheckboxContainerError');
  }
} else {
  if ($this->_align === 'horizontal') {
      $options['templates']['checkboxFormGroup'] = $this->templater()->get('customSwitchFormGroup');                          
  } else {
      $options['templates']['checkboxContainer'] = $this->templater()->get('customSwitchContainer');
      $options['templates']['checkboxContainerError'] = $this->templater()->get('customSwitchContainerError');
  }
}

and:

if ($inline ||
    $this->_align === 'inline'
) {
    if (!$custom) {
        $options['templates']['checkboxContainer'] = $this->templater()->get('checkboxInlineContainer');
        $options['templates']['checkboxContainerError'] = $this->templater()->get('checkboxInlineContainerError');
    } else {
        if (empty($options['switch'])) {
          $options['templates']['checkboxContainer'] = $this->templater()->get('customCheckboxInlineContainer');
          $options['templates']['checkboxContainerError'] = $this->templater()->get('customCheckboxInlineContainerError');
        } else {
          $options['templates']['checkboxContainer'] = $this->templater()->get('customSwitchInlineContainer');
          $options['templates']['checkboxContainerError'] = $this->templater()->get('customSwitchInlineContainerError');
        }
    }
}

So my calling code is simply:

$this->Form->control('is_active', ['custom' => true, 'switch' => true]);

I've no need for multiswitch controls, but I believe code to add would be straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants