├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── CHANGE.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── CheckboxX.php ├── CheckboxXAsset.php └── KrajeeFlatBlueThemeAsset.php /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to yii2-checkbox-x 2 | =============================== 3 | Looking to contribute something to yii2-checkbox-x? **Here's how you can help.** 4 | 5 | Please take a moment to review this document in order to make the contribution 6 | process easy and effective for everyone involved. 7 | 8 | Following these guidelines helps to communicate that you respect the time of 9 | the developers managing and developing this open source project. In return, 10 | they should reciprocate that respect in addressing your issue or assessing 11 | patches and features. 12 | 13 | Using the issue tracker 14 | ----------------------- 15 | When [reporting bugs][reporting-bugs] or 16 | [requesting features][requesting-features], the 17 | [issue tracker on GitHub][issue-tracker] is the recommended channel to use. 18 | 19 | The issue tracker **is not** a place for support requests. Refer the 20 | [extension documentation and demos](http://demos.krajee.com/checkbox-x) and/or refer to the 21 | [webtips Q & A forum](http://webtips.krajee.com/questions) which are the better places to get help. 22 | 23 | Reporting bugs with yii2-checkbox-x 24 | ----------------------------------- 25 | We really appreciate clear bug reports that _consistently_ show an issue 26 | _within yii2-checkbox-x_. 27 | 28 | The ideal bug report follows these guidelines: 29 | 30 | 1. **Use the [GitHub issue search][issue-search]** — Check if the issue 31 | has already been reported. 32 | 2. **Check if the issue has been fixed** — Try to reproduce the problem 33 | using the code in the `master` branch. 34 | 3. **Isolate the problem** — Try to share a demo or a test case that 35 | consistently reproduces the problem. 36 | 37 | Please try to be as detailed as possible in your bug report, especially if an 38 | isolated test case cannot be made. Some useful questions to include the answer 39 | to are: 40 | 41 | - What steps can be used to reproduce the issue? 42 | - What is the bug and what is the expected outcome? 43 | - What browser(s) and Operating System have you tested with? 44 | - Does the bug happen consistently across all tested browsers? 45 | - What version of jQuery are you using? And what version of yii2-checkbox-x? 46 | - Are you using yii2-checkbox-x with other plugins? 47 | 48 | All of these questions will help others fix and identify any potential bugs. 49 | 50 | Requesting features in yii2-checkbox-x 51 | ------------------------------------------ 52 | Before starting work on a major feature for yii2-checkbox-x, **read the 53 | [documentation](http://demos.krajee.com/checkbox-x) first** or you may risk spending a considerable amount of 54 | time on something which the project developers are not interested in bringing into the project. 55 | 56 | ### Submitting a pull request 57 | 58 | We use GitHub's pull request system for submitting patches. Here are some 59 | guidelines to follow when creating the pull request for your fix. 60 | 61 | 1. Make sure to create a ticket for your pull request. This will serve as the 62 | bug ticket, and any discussion about the bug will take place there. Your pull 63 | request will be focused on the specific changes that fix the bug. 64 | 2. Make sure to reference the ticket you are fixing within your pull request. 65 | This will allow us to close off the ticket once we merge the pull request, or 66 | follow up on the ticket if there are any related blocking issues. 67 | 3. Explain why the specific change was made. Not everyone who is reviewing your 68 | pull request will be familiar with the problem it is fixing. 69 | 4. Run your tests first. If your tests aren't passing, the pull request won't 70 | be able to be merged. If you're breaking existing tests, make sure that you 71 | aren't causing any breaking changes. 72 | 5. Only include source changes. While it's not required, only including changes 73 | from the `src` directory will prevent merge conflicts from occuring. Making 74 | this happen can be as a simple as not committing changes from the `dist` 75 | directory. 76 | 77 | By following these steps, you will make it easier for your pull request to be 78 | reviewed and eventually merged. 79 | 80 | Triaging issues and pull requests 81 | --------------------------------- 82 | Anyone can help the project maintainers triage issues and review pull requests. 83 | 84 | ### Handling new issues 85 | 86 | yii2-checkbox-x regularly receives new issues which need to be tested and organized. 87 | 88 | When a new issue that comes in that is similar to another existing issue, it 89 | should be checked to make sure it is not a duplicate. Duplicates issues should 90 | be marked by replying to the issue with "Duplicate of #[issue number]" where 91 | `[issue number]` is the url or issue number for the existing issue. This will 92 | allow the project maintainers to quickly close off additional issues and keep 93 | the discussion focused within a single issue. 94 | 95 | If you can test issues that are reported to yii2-checkbox-x that contain test cases and 96 | confirm under what conditions bugs happen, that will allow others to identify 97 | what causes a bug quicker. 98 | 99 | ### Reviewing pull requests 100 | 101 | It is very common for pull requests to be opened for issues that contain a clear 102 | solution to the problem. These pull requests should be rigorously reviewed by 103 | the community before being accepted. If you are not sure about a piece of 104 | submitted code, or know of a better way to do something, do not hesitate to make 105 | a comment on the pull request. 106 | 107 | ### Reviving old tickets 108 | 109 | If you come across tickets which have not been updated for a while, you are 110 | encouraged to revive them. While this can be as simple as saying `:+1:`, it is 111 | best if you can include more information on the issue. Common bugs and feature 112 | requests are more likely to be fixed, whether it is by the community or the 113 | developers, so keeping tickets up to date is encouraged. 114 | 115 | Licensing 116 | --------- 117 | 118 | It should also be made clear that **all code contributed to yii2-checkbox-x** must be 119 | licensable under the [BSD-3 license][licensing]. Code that cannot be released 120 | under this license **cannot be accepted** into the project. 121 | 122 | [issue-search]: https://github.com/kartik-v/yii2-checkbox-x/search?q=&type=Issues 123 | [issue-tracker]: https://github.com/kartik-v/yii2-checkbox-x/issues 124 | [licensing]: https://github.com/kartik-v/yii2-checkbox-x/blob/master/LICENSE.md 125 | [reporting-bugs]: #reporting-bugs-with-yii2-checkbox-x 126 | [requesting-features]: #requesting-features-in-yii2-checkbox-x -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | 3 | - [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate. 4 | - [ ] The issue still exists against the latest `master` branch of yii2-checkbox-x. 5 | - [ ] This is not an usage question. I confirm having gone through and read the [documentation and demos](http://demos.krajee.com/checkbox-x). 6 | - [ ] This is not a general programming / coding question. (Those should be directed to the [webtips Q & A forum](http://webtips.krajee.com/questions)). 7 | - [ ] I have attempted to find the simplest possible steps to reproduce the issue. 8 | - [ ] I have included a failing test as a pull request (Optional). 9 | 10 | ## Steps to reproduce the issue 11 | 12 | 1. 13 | 2. 14 | 3. 15 | 16 | ## Expected behavior and actual behavior 17 | 18 | When I follow those steps, I see... 19 | 20 | I was expecting... 21 | 22 | ## Environment 23 | 24 | #### Browsers 25 | 26 | - [ ] Google Chrome 27 | - [ ] Mozilla Firefox 28 | - [ ] Internet Explorer 29 | - [ ] Safari 30 | 31 | #### Operating System 32 | 33 | - [ ] Windows 34 | - [ ] Mac OS X 35 | - [ ] Linux 36 | - [ ] Mobile 37 | 38 | #### Libraries 39 | 40 | - jQuery version: 41 | - yii2-checkbox-x version: 42 | 43 | ## Isolating the problem 44 | 45 | - [ ] This bug happens [on the demos page](https://demos.krajee.com/checkbox-x) 46 | - [ ] The bug happens consistently across all tested browsers 47 | - [ ] This bug happens when using yii2-checkbox-x without other plugins. -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Scope 2 | This pull request includes a 3 | 4 | - [ ] Bug fix 5 | - [ ] New feature 6 | - [ ] Translation 7 | 8 | ## Changes 9 | The following changes were made (this change is also documented in the [change log](https://github.com/kartik-v/yii2-checkbox-x/blob/master/CHANGE.md)): 10 | 11 | - 12 | - 13 | - 14 | 15 | ## Related Issues 16 | If this is related to an existing ticket, include a link to it as well. -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - bug 8 | - enhancement 9 | - pinned 10 | - security 11 | # Label to use when marking an issue as stale 12 | staleLabel: wontfix 13 | # Comment to post when marking an issue as stale. Set to `false` to disable 14 | markComment: > 15 | This issue has been automatically marked as stale because it has not had 16 | recent activity. It will be closed if no further activity occurs. Thank you 17 | for your contributions. 18 | # Comment to post when closing a stale issue. Set to `false` to disable 19 | closeComment: false -------------------------------------------------------------------------------- /CHANGE.md: -------------------------------------------------------------------------------- 1 | Change Log: `yii2-checkbox-x` 2 | ============================= 3 | 4 | ## Version 1.0.7 5 | 6 | **Date**: 10-Jan-2022 7 | 8 | - Enhance & standardize php docs for new website https://docs.krajee.com. 9 | 10 | ## Version 1.0.6 11 | 12 | **Date**: 01-Sep-2021 13 | 14 | - (enh #17): Enhancements to support Bootstrap v5.x. 15 | 16 | ## Version 1.0.5 17 | 18 | **Date**: 01-Sep-2021 19 | 20 | - (enh #16): Set more correct icon defaults for bootstrap 4.x. 21 | 22 | ## Version 1.0.4 23 | 24 | **Date**: 09-Oct-2018 25 | 26 | - Bump composer dependencies. 27 | - Add github contribution and issue/PR logging templates. 28 | - Enhance PHP Documentation for all classes and methods in the extension. 29 | - Add branch alias for dev-master latest release. 30 | 31 | ## Version 1.0.3 32 | 33 | **Date**: 11-Jan-2016 34 | 35 | - (enh #14): Enhancements for PJAX based reinitialization. Complements enhancements in kartik-v/yii2-krajee-base#52 and kartik-v/yii2-krajee-base#53. 36 | 37 | ## Version 1.0.2 38 | 39 | **Date**: 20-Sep-2015 40 | 41 | - Better label generation. 42 | - Add support for theme. 43 | 44 | ## Version 1.0.1 45 | 46 | **Date**: 17-Jun-2015 47 | 48 | - (enh #10): Set composer ## Version dependencies. 49 | - (enh #9): New `labelSettings` property to allow configuring checkbox labels better. 50 | - (enh #8): New `autoLabel` property to allow automatic configuration of label text, styles, and positions. 51 | - (enh #7): New `initInputType` property to set input type for initializing bootstrap-checkbox-x plugin. 52 | - (enh #2): Enhance widget to use updated plugin registration from Krajee base 53 | - Code formatting updates as per Yii2 coding style. 54 | 55 | ## Version 1.0.0 56 | 57 | **Date**: 09-Nov-2014 58 | 59 | - Initial release 60 | - Set dependency on Krajee base component 61 | - PSR 4 alias change 62 | - Stable release -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 - 2022, Kartik Visweswaran 2 | Krajee.com 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 15 | * Neither the names of Kartik Visweswaran or Krajee nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Krajee Logo 4 | 5 |
6 | yii2-checkbox-x 7 |
8 | Donate 10 |       11 | kartikv 12 |

13 | 14 |
15 | 16 | [![Stable Version](https://poser.pugx.org/kartik-v/yii2-checkbox-x/v/stable)](https://packagist.org/packages/kartik-v/yii2-checkbox-x) 17 | [![Unstable Version](https://poser.pugx.org/kartik-v/yii2-checkbox-x/v/unstable)](https://packagist.org/packages/kartik-v/yii2-checkbox-x) 18 | [![License](https://poser.pugx.org/kartik-v/yii2-checkbox-x/license)](https://packagist.org/packages/kartik-v/yii2-checkbox-x) 19 | [![Total Downloads](https://poser.pugx.org/kartik-v/yii2-checkbox-x/downloads)](https://packagist.org/packages/kartik-v/yii2-checkbox-x) 20 | [![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-checkbox-x/d/monthly)](https://packagist.org/packages/kartik-v/yii2-checkbox-x) 21 | [![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-checkbox-x/d/daily)](https://packagist.org/packages/kartik-v/yii2-checkbox-x) 22 | 23 |
24 | 25 | An extended checkbox widget for Yii Framework 2 based on the [bootstrap-checkbox-x jQuery plugin](http://plugins.krajee.com/checkbox-x) by Krajee. This widget 26 | allows three checkbox states and includes additional styles. The plugin uses Bootstrap markup, glyphs, and CSS 3 styling by default, but it can be overridden 27 | with any other markup. 28 | 29 | > NOTE: The checkbox plugin stores the values as integer format (and not boolean format) for checked and unchecked states. 30 | 31 | ## Features 32 | 33 | - The plugin offers the following three states and values for the checkboxes (note the integer values): 34 | - `1`: Checkbox is checked. 35 | - `0`: Checkbox is unchecked. 36 | - `null`: Checkbox is indeterminate. 37 | - You can set the plugin to allow **three states** or the default **two states** for the checkbox. 38 | - Specifically uses Bootstrap styles & glyphs (supports 3.x, 4.x. 5.x). One can configure the checked, unchecked, and indeterminate icons to be shown for the checkboxes. 39 | - Special CSS 3 styling, to enhance the control to look like any Bootstrap form control. Supports the `has-error`, `has-success`, `has-warning` 40 | styling states like other Bootstrap form-controls. 41 | - Plugin CSS styling automatically defaults the checkboxes to inline display. You can also control the markup for block display like in checkbox lists. 42 | - You can add a `label` before or after with a `for` attribute and click on the label to change the checkbox values. Alternatively you can enclose the 43 | input within a `label` tag as well. 44 | - Ability to navigate to the checkbox controls via keyboard, and modify the values using the `space` bar on the keyboard. 45 | - Ability to size the checkbox control. Five prebuilt size templates are available `xl`, `lg`, `md`, `sm`, and `xs`. 46 | - Triggers JQuery events for advanced development. The plugin automatically triggers the `change` event for the input, whenever the checkbox value is changed via clicking. Events currently available are `change` and `reset`. 47 | - Ability to access methods and refresh the input dynamically via javascript at runtime. 48 | - Disabled and readonly checkbox input support. 49 | - Size of the entire plugin (JS and CSS) is less than 2KB when minified and gzipped. Its about 6KB when minified without gzipping (about 3KB for the JS and 3KB for the CSS). 50 | 51 | ### Docs & Demo 52 | You can see detailed [docs and demos](http://demos.krajee.com/checkbox-x) and the API [code documentation](https://docs.krajee.com/kartik-checkbox-checkboxx) on usage of the extension. 53 | 54 | ### Release Changes 55 | Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-checkbox-x/blob/master/CHANGE.md) for details on changes to various releases. 56 | 57 | ## Installation 58 | 59 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 60 | 61 | > NOTE: Check the [composer.json](https://github.com/kartik-v/yii2-checkbox-x/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json. 62 | 63 | Either run 64 | 65 | ``` 66 | $ php composer.phar require kartik-v/yii2-checkbox-x "@dev" 67 | ``` 68 | 69 | or add 70 | 71 | ``` 72 | "kartik-v/yii2-checkbox-x": "@dev" 73 | ``` 74 | 75 | to the ```require``` section of your `composer.json` file. 76 | 77 | ## Usage 78 | 79 | ### CheckboxX 80 | 81 | ```php 82 | use kartik\checkbox\CheckboxX; 83 | echo CheckboxX::widget([ 84 | 'model' => $model, 85 | 'attribute' => 'status', 86 | 'pluginOptions' => [ 87 | 'threeState' => true, 88 | 'size' => 'lg' 89 | ] 90 | ]); 91 | ``` 92 | 93 | ## License 94 | 95 | **yii2-checkbox-x** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kartik-v/yii2-checkbox-x", 3 | "description": "Extended checkbox widget for bootstrap with three states and additional styles.", 4 | "keywords": [ 5 | "bootstrap", 6 | "checkbox", 7 | "jquery", 8 | "three", 9 | "state", 10 | "indeterminate", 11 | "null" 12 | ], 13 | "homepage": "https://github.com/kartik-v/yii2-checkbox-x", 14 | "type": "yii2-extension", 15 | "license": "BSD-3-Clause", 16 | "authors": [ 17 | { 18 | "name": "Kartik Visweswaran", 19 | "email": "kartikv2@gmail.com", 20 | "homepage": "http://www.krajee.com/" 21 | } 22 | ], 23 | "require": { 24 | "kartik-v/yii2-krajee-base": ">=3.0.0", 25 | "kartik-v/bootstrap-checkbox-x": "~1.5" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "kartik\\checkbox\\": "src" 30 | } 31 | }, 32 | "extra": { 33 | "branch-alias": { 34 | "dev-master": "1.0.x-dev" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CheckboxX.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2022 7 | * @version 1.0.7 8 | */ 9 | 10 | namespace kartik\checkbox; 11 | 12 | use yii\base\InvalidConfigException; 13 | use yii\helpers\Html; 14 | use yii\helpers\ArrayHelper; 15 | use kartik\base\InputWidget; 16 | 17 | /** 18 | * CheckboxX is an extended checkbox widget for Yii Framework 2 based on the 19 | * [bootstrap-checkbox-x](http://plugins.krajee.com/checkbox-x) plugin by Krajee. 20 | * This widget allows three checkbox states and includes additional styles. 21 | * 22 | * For example, 23 | * 24 | * ```php 25 | * use kartik\checkbox\CheckboxX; 26 | * echo CheckboxX::widget([ 27 | * 'model' => $model, 28 | * 'attribute' => 'status', 29 | * 'pluginOptions' => [ 30 | * 'threeState' => true, 31 | * 'size' => 'lg' 32 | * ] 33 | * ]); 34 | * ``` 35 | * 36 | * @see http://plugins.krajee.com/checkbox-x 37 | * @see http://github.com/kartik-v/bootstrap-checkbox-x 38 | * 39 | * @author Kartik Visweswaran 40 | * 41 | */ 42 | class CheckboxX extends InputWidget 43 | { 44 | /** 45 | * @var string text input type 46 | */ 47 | const INPUT_TEXT = 'textInput'; 48 | /** 49 | * @var string checkbox input type 50 | */ 51 | const INPUT_CHECKBOX = 'checkbox'; 52 | /** 53 | * @var string position label to the left of the checkbox 54 | */ 55 | const LABEL_LEFT = 'left'; 56 | /** 57 | * @var string position label to the right of the checkbox 58 | */ 59 | const LABEL_RIGHT = 'right'; 60 | 61 | /** 62 | * @var string initialization input type. Note, the widget by default uses a text input to initialize the plugin 63 | * instead of checkbox for better label styling, alignment and using templates within ActiveField. Can be one of 64 | * [[INPUT_TEXT]] or [[INPUT_CHECKBOX]]. Defaults to [[INPUT_TEXT]]. 65 | */ 66 | public $initInputType = self::INPUT_TEXT; 67 | 68 | /** 69 | * @var boolean whether to automatically generate, style, and position labels with respect to the checkbox x. If this is 70 | * `true`, the labels will automatically be positioned and styled based on label settings. When this is set to 71 | * `true` and you have set the `model` and `attribute`, the label will be automatically generated. If you are not 72 | * using this with a model, then you must set the property `labelSettings['label']` for automatic label styling 73 | * to work. 74 | * 75 | * NOTE: If this is `true`, and you are using the widget within yii ActiveField, then you must disable the active 76 | * field label generation to avoid duplicate labels. For example: 77 | * 78 | * ```php 79 | * echo $form->field($model, 'attr')->widget(CheckboxX::classname(), [ 80 | * 'autoLabel'=>true 81 | * ])->label(false); 82 | * ``` 83 | */ 84 | public $autoLabel = false; 85 | 86 | /** 87 | * @var array the settings for the label. The following properties are recognized 88 | * - `label`: _string_, the label to be used. When using with model, this will be automatically generated 89 | * if not set. 90 | * - `position`: _string_, the position of the label with respect to the checkbox. Must be one of[[LABEL_LEFT]] or 91 | * [[LABEL_RIGHT]]. Defaults to [[LABEL_RIGHT]] if not set. 92 | * - `options`: _array_, the HTML attributes for the label. 93 | */ 94 | public $labelSettings = []; 95 | 96 | /** 97 | * @inheritdoc 98 | */ 99 | public $pluginName = 'checkboxX'; 100 | 101 | /** 102 | * @inheritdoc 103 | */ 104 | public function run() 105 | { 106 | $this->initOptions(); 107 | $this->registerAssets(); 108 | $this->renderWidget(); 109 | } 110 | 111 | /** 112 | * Initialize [[CheckboxX]] widget and the plugin options for 113 | * [bootstrap-checkbox-x](http://plugins.krajee.com/checkbox-x). 114 | * 115 | * @throws InvalidConfigException 116 | */ 117 | protected function initOptions() 118 | { 119 | if ($this->pluginLoading) { 120 | Html::addCssClass($this->options, 'cbx-loading'); 121 | } 122 | $txt = self::INPUT_TEXT; 123 | $cbx = self::INPUT_CHECKBOX; 124 | if ($this->initInputType !== $txt && $this->initInputType !== $cbx) { 125 | throw new InvalidConfigException("The 'initInputType' property must be one of '{$txt}' or '{$cbx}'."); 126 | } 127 | if (empty($this->pluginOptions['iconChecked'])) { 128 | $this->pluginOptions['iconChecked'] = $this->isBs4() ? '' : 129 | ''; 130 | } 131 | 132 | } 133 | 134 | /** 135 | * Initializes markup & styling for checkbox, label, and parses label positions. 136 | */ 137 | public function renderWidget() 138 | { 139 | if (empty($this->labelSettings['label']) && !$this->autoLabel) { 140 | echo $this->getInput($this->initInputType); 141 | return; 142 | } 143 | $label = ArrayHelper::getValue($this->labelSettings, 'label', ''); 144 | $options = ArrayHelper::getValue($this->labelSettings, 'options', []); 145 | $position = ArrayHelper::getValue($this->labelSettings, 'position', self::LABEL_RIGHT); 146 | Html::addCssClass($options, 'cbx-label'); 147 | if ($this->disabled || $this->readonly || 148 | ArrayHelper::getValue($this->options, 'disabled', false) || 149 | ArrayHelper::getValue($this->options, 'readonly', false) 150 | ) { 151 | Html::addCssClass($options, 'disabled'); 152 | } 153 | $label = $this->hasModel() && empty($label) ? 154 | Html::activeLabel($this->model, $this->attribute, $options) : 155 | Html::label($label, $this->options['id'], $options); 156 | if ($this->initInputType !== self::INPUT_TEXT) { 157 | $this->options['label'] = ''; 158 | } 159 | $input = $this->getInput($this->initInputType); 160 | echo ($position === self::LABEL_RIGHT) ? $input . $label : $label . $input; 161 | } 162 | 163 | /** 164 | * Registers the client assets for the [[CheckboxX]] widget. 165 | */ 166 | public function registerAssets() 167 | { 168 | $view = $this->getView(); 169 | CheckboxXAsset::register($view); 170 | if (!empty($this->pluginOptions['theme']) && $this->pluginOptions['theme'] === 'krajee-flatblue') { 171 | KrajeeFlatBlueThemeAsset::register($view); 172 | } 173 | $this->registerPlugin($this->pluginName); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/CheckboxXAsset.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2022 7 | * @version 1.0.7 8 | */ 9 | 10 | namespace kartik\checkbox; 11 | 12 | use kartik\base\AssetBundle; 13 | 14 | /** 15 | * Asset bundle for [[CheckboxX]] widget. Includes assets from 16 | * [bootstrap-checkbox-x](http://plugins.krajee.com/checkbox-x) plugin by Krajee. 17 | * 18 | * @see http://plugins.krajee.com/checkbox-x 19 | * @see http://github.com/kartik-v/bootstrap-checkbox-x 20 | * 21 | * @author Kartik Visweswaran 22 | */ 23 | class CheckboxXAsset extends AssetBundle 24 | { 25 | /** 26 | * @inheritdoc 27 | */ 28 | public function init() 29 | { 30 | $this->setSourcePath('@vendor/kartik-v/bootstrap-checkbox-x'); 31 | $this->setupAssets('css', ['css/checkbox-x']); 32 | $this->setupAssets('js', ['js/checkbox-x']); 33 | parent::init(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/KrajeeFlatBlueThemeAsset.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2022 7 | * @version 1.0.7 8 | */ 9 | 10 | namespace kartik\checkbox; 11 | 12 | use kartik\base\AssetBundle; 13 | 14 | /** 15 | * Asset bundle for the Krajee flatblue theme used in [[CheckboxX]] widget. Includes assets from 16 | * [bootstrap-checkbox-x](http://plugins.krajee.com/checkbox-x) plugin by Krajee. 17 | * 18 | * @see http://plugins.krajee.com/checkbox-x 19 | * @see http://github.com/kartik-v/bootstrap-checkbox-x 20 | * 21 | * @author Kartik Visweswaran 22 | */ 23 | class KrajeeFlatBlueThemeAsset extends AssetBundle 24 | { 25 | /** 26 | * @inheritdoc 27 | */ 28 | public $depends = [ 29 | 'kartik\checkbox\CheckboxXAsset' 30 | ]; 31 | 32 | /** 33 | * @inheritdoc 34 | */ 35 | public function init() 36 | { 37 | $this->setSourcePath('@vendor/kartik-v/bootstrap-checkbox-x'); 38 | $this->setupAssets('css', ['css/theme-krajee-flatblue']); 39 | parent::init(); 40 | } 41 | } 42 | --------------------------------------------------------------------------------