diff --git a/resources/views/form/belongsto.blade.php b/resources/views/form/belongsto.blade.php index baf06ac67f..a2b6d40a99 100644 --- a/resources/views/form/belongsto.blade.php +++ b/resources/views/form/belongsto.blade.php @@ -1,12 +1,12 @@ -
+
- + -
+
@include('admin::form.error') - + @@ -27,6 +28,5 @@
@include('admin::form.help-block') -
diff --git a/resources/views/form/belongstomany.blade.php b/resources/views/form/belongstomany.blade.php index 9f6100f19e..251be01490 100644 --- a/resources/views/form/belongstomany.blade.php +++ b/resources/views/form/belongstomany.blade.php @@ -1 +1 @@ -@include('admin::form.belongsto',['multiple' => true]) +@include('admin::form.belongsto',['multiple'=>true]) diff --git a/resources/views/form/morphto.blade.php b/resources/views/form/morphto.blade.php new file mode 100644 index 0000000000..fc24f9c27b --- /dev/null +++ b/resources/views/form/morphto.blade.php @@ -0,0 +1,2 @@ +@include('admin::form.belongsto') + diff --git a/src/Form/Field/BelongsTo.php b/src/Form/Field/BelongsTo.php index ba1b882344..e288327151 100644 --- a/src/Form/Field/BelongsTo.php +++ b/src/Form/Field/BelongsTo.php @@ -38,8 +38,8 @@ protected function addScript() $.get(url, function (data) { modal.find('.modal-body').html(data); modal.find('.select').iCheck({ - radioClass:'iradio_minimal-blue', - checkboxClass:'icheckbox_minimal-blue' + radioClass: 'iradio_minimal-blue', + checkboxClass: 'icheckbox_minimal-blue' }); modal.find('.box-header:first').hide(); diff --git a/src/Form/Field/CanCascadeFields.php b/src/Form/Field/CanCascadeFields.php index b4d3deecbb..e8221109a7 100644 --- a/src/Form/Field/CanCascadeFields.php +++ b/src/Form/Field/CanCascadeFields.php @@ -210,7 +210,7 @@ protected function addCascadeScript() 'oneNotIn': function(a, b) { return a.filter(v => b.includes(v)).length == 0; }, }; var cascade_groups = {$cascadeGroups}; - + cascade_groups.forEach(function (event) { var default_value = '{$this->getValueByJs()}' + ''; var class_name = event.class; @@ -218,11 +218,9 @@ protected function addCascadeScript() $('.'+class_name+'').removeClass('hide'); } }); - - $('{$this->getElementClassSelector()}').on('{$this->cascadeEvent}', function (e) { + $('{$this->getElementClassSelector()}').on('{$this->cascadeEvent}', function (e) { {$this->getFormFrontValue()} - cascade_groups.forEach(function (event) { var group = $('div.cascade-group.'+event.class); if( operator_table[event.operator](checked, event.value) ) { diff --git a/src/Form/Field/MorphTo.php b/src/Form/Field/MorphTo.php index 19c949ecda..26e07b75d8 100644 --- a/src/Form/Field/MorphTo.php +++ b/src/Form/Field/MorphTo.php @@ -2,18 +2,40 @@ namespace Encore\Admin\Form\Field; +use Illuminate\Support\Str; + class MorphTo extends BelongsTo { protected $typeColumn; protected $morphClass; - protected $view = 'admin::form.belongsTo'; + public function __construct($morphName, $arguments = []) + { + $this->typeColumn = $morphName . '_type'; + $column = $morphName . '_id'; + parent::__construct($column, $arguments); + + if (empty($arguments[1])) { + $this->label = Str::title($morphName); + } - public function __construct($column, $arguments = []) + $this->addVariables([ + 'typeColumn' => $this->typeColumn, + 'morphClass' => $this->morphClass() + ]); + } + + /** + * @return mixed + */ + public function morphClass() { - $this->typeColumn = $column . '_type'; - parent::__construct($column . '_id', $arguments); + if (!$this->morphClass) { + $modelClass = (new $this->selectable)->model; + $this->morphClass = (new $modelClass)->getMorphClass(); + } + return $this->morphClass; } public function value($value = null) @@ -35,16 +57,4 @@ public function currenMorphClass() { return $this->form->model()->{$this->typeColumn}; } - - /** - * @return mixed - */ - public function morphClass() - { - if (!$this->morphClass) { - $modelClass = (new $this->selectable)->model; - $this->morphClass = (new $modelClass)->getMorphClass(); - } - return $this->morphClass; - } }