Completed
Push — master ( 82be35...1537c0 )
by Song
02:28
created

src/Form/Field/CheckboxButton.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Admin;
6
7 View Code Duplication
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();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::fieldRender(); of type string|Illuminate\View\V...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 50 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
51
    }
52
}
53