| @@ 7-52 (lines=46) @@ | ||
| 4 | ||
| 5 | use Encore\Admin\Admin; |
|
| 6 | ||
| 7 | class CheckboxButton extends Checkbox |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @var string |
|
| 11 | */ |
|
| 12 | protected $cascadeEvent = 'change'; |
|
| 13 | ||
| 14 | protected function addScript() |
|
| 15 | { |
|
| 16 | $script = <<<SCRIPT |
|
| 17 | $('.checkbox-group-toggle label').click(function(e) { |
|
| 18 | e.stopPropagation(); |
|
| 19 | e.preventDefault(); |
|
| 20 | ||
| 21 | if ($(this).hasClass('active')) { |
|
| 22 | $(this).removeClass('active'); |
|
| 23 | $(this).find('input').prop('checked', false); |
|
| 24 | } else { |
|
| 25 | $(this).addClass('active'); |
|
| 26 | $(this).find('input').prop('checked', true); |
|
| 27 | } |
|
| 28 | ||
| 29 | $(this).find('input').trigger('change'); |
|
| 30 | }); |
|
| 31 | SCRIPT; |
|
| 32 | ||
| 33 | Admin::script($script); |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * {@inheritdoc} |
|
| 38 | */ |
|
| 39 | public function render() |
|
| 40 | { |
|
| 41 | $this->addScript(); |
|
| 42 | ||
| 43 | $this->addCascadeScript(); |
|
| 44 | ||
| 45 | $this->addVariables([ |
|
| 46 | 'options' => $this->options, |
|
| 47 | 'checked' => $this->checked, |
|
| 48 | ]); |
|
| 49 | ||
| 50 | return parent::fieldRender(); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||
| @@ 7-45 (lines=39) @@ | ||
| 4 | ||
| 5 | use Encore\Admin\Admin; |
|
| 6 | ||
| 7 | class RadioButton extends Radio |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @var string |
|
| 11 | */ |
|
| 12 | protected $cascadeEvent = 'change'; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * |
|
| 16 | */ |
|
| 17 | protected function addScript() |
|
| 18 | { |
|
| 19 | $script = <<<SCRIPT |
|
| 20 | $('.radio-group-toggle label').click(function() { |
|
| 21 | $(this).parent().children().removeClass('active'); |
|
| 22 | $(this).addClass('active'); |
|
| 23 | }); |
|
| 24 | SCRIPT; |
|
| 25 | ||
| 26 | Admin::script($script); |
|
| 27 | } |
|
| 28 | ||
| 29 | /** |
|
| 30 | * {@inheritdoc} |
|
| 31 | */ |
|
| 32 | public function render() |
|
| 33 | { |
|
| 34 | $this->addScript(); |
|
| 35 | ||
| 36 | $this->addCascadeScript(); |
|
| 37 | ||
| 38 | $this->addVariables([ |
|
| 39 | 'options' => $this->options, |
|
| 40 | 'checked' => $this->checked, |
|
| 41 | ]); |
|
| 42 | ||
| 43 | return parent::fieldRender(); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||