
最佳答案
- 是laravel-admin的bug
- 想办法修改源码里面这个方法: SwitchField@render
- 要修改的地方,我写了注释
讨论数量:
在protected function form()
添加
$form->number('status','标签'); //当然可以换成switch
在grid
编辑的
都是调用form()
,因此form()
必须存在要编辑的字段。
- 是laravel-admin的bug
- 想办法修改源码里面这个方法: SwitchField@render
- 要修改的地方,我写了注释
<?php namespace Encore\Admin\Form\Field; use Encore\Admin\Form\Field; use Illuminate\Support\Arr; class SwitchField extends Field { public function render() { $this->script = <<<EOT $('{$this->getElementClassSelector()}.la_checkbox').bootstrapSwitch({ size:'{$this->size}', onText: '{$this->states['on']['text']}', offText: '{$this->states['off']['text']}', onColor: '{$this->states['on']['color']}', offColor: '{$this->states['off']['color']}', onSwitchChange: function(event, state) { //这一行是源码 $(event.target).closest('.bootstrap-switch').next().val(state ? 'on' : 'off').change(); //修改成这样,value就是0、1了 $(event.target).closest('.bootstrap-switch').next().val(state ? '{$this->states['on']['value']}' : '{$this->states['off']['value']}').change(); } }); EOT; return parent::render(); } }