Laravel-admin: Bug in getElementClassString in hasMany

Created on 10 Feb 2019  ·  3Comments  ·  Source: z-song/laravel-admin

  • Laravel-admin: Latest

Description:

When I use hasMany + try to load ckeditor, he does not load properly.

$form->tab($lang['name'], function ($form) use($key, $lang) {

    $form->hasMany('trans' . $key, function (Form\NestedForm $form) use($key, $lang) {
        $form->text('title', 'Title ');
        $form->text('meta_t', 'Meta Title');
        $form->text('meta_d', 'Meta Description');
        $form->ckeditor('text');
    });
});

HTML:

<textarea class="form-control transen text" id="text" name="transen[3][text]" placeholder="Input Text"  >en текст</textarea>

JS init:

$('textarea.transen text').ckeditor();

But should be:

$('textarea.transen').ckeditor();

Or:

$('textarea.transen #text').ckeditor();

And id="text" should be unique

wontfix

Most helpful comment

For this problem, I implemented a solution in my code. I edited render() function in app/Admin/Extensions/Form/CKEditor.php

    public function render()
    {
        $class = explode(' ', $this->getElementClassString())[0];
        $this->script = "$('textarea.{$class}').ckeditor();";
        return parent::render();
    }

All 3 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

For this problem, I implemented a solution in my code. I edited render() function in app/Admin/Extensions/Form/CKEditor.php

    public function render()
    {
        $class = explode(' ', $this->getElementClassString())[0];
        $this->script = "$('textarea.{$class}').ckeditor();";
        return parent::render();
    }

Thats works for me

App\Admin\Extensions\Form\CKEditor.php

<?php

namespace App\Admin\Extensions\Form;

use Encore\Admin\Form\Field;

class CKEditor extends Field
{

    public static $js = [
        'vendor/laravel-admin-ext/ckeditor/ckeditor.js',
        'vendor/laravel-admin-ext/ckeditor/adapters/jquery.js',
    ];

    protected $view = 'admin.ckeditor';

    public function render()
    {
        $class = explode(' ', $this->getElementClassString())[0];
        $this->script = "$('textarea.{$class}').ckeditor();";
        return parent::render();
    }
}

App\Admin\bootstrap.php:

use App\Admin\Extensions\Form\CKEditor;

.....

Encore\Admin\Form::extend('ckeditor', CKEditor::class);

resources\views\admin\ckeditor.blade.php:

<div class="form-group {!! !$errors->has($errorKey) ?: 'has-error' !!}">

    <label for="{{$id}}" class="col-sm-2 control-label">{{$label}}</label>

    <div class="col-sm-8">

        @include('admin::form.error')

        <textarea class="form-control {{ $class }}" name="{{$name}}" placeholder="{{ $placeholder }} ckeditor_class" {!! $attributes !!} >{{ old($column, $value) }}</textarea>

        @include('admin::form.help-block')

    </div>
</div>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

vlongen picture vlongen  ·  3Comments

chenyongmin picture chenyongmin  ·  3Comments

taimaiduc picture taimaiduc  ·  3Comments

abufalbo picture abufalbo  ·  3Comments

evans-kim picture evans-kim  ·  3Comments