Laravel 5.5本地化和CKEditor

时间:2018-09-05 18:59:49

标签: laravel ckeditor

我想用ckeditor替换多个文本区域(Content En和Content Ru),但是它们都具有相同的ID。怎么做,因为加载一个编辑器后,它停止了。

表格:

{!! Form::open([ 'route' => 'portfolio.store', 'files' => 'true']) !!}

        @foreach(config('translatable.locales') as $locale)
            <div class="form-group">
                <label for="translation[{{$locale}}][title]"><strong>Title ({{$locale}})</strong></label>
                <input type="text" id="title"
                       name="translation[{{$locale}}][title]"
                       class="form-control"
                       value="{{ old('translation.'. $locale.'.title')  }}">
            </div>

            <div class="form-group">
                <label for="translation[{{$locale}}][content]"><strong>Content ({{$locale}})</strong></label>
                <textarea name="translation[{{$locale}}][content]"
                          id="content"
                          class="form-control"
                          cols="30"
                          rows="10">{{ old('translation.'. $locale.'.content') }}</textarea>
            </div>
        @endforeach

            <div class="form-group">
                <label for="image"><strong>Image</strong></label>
                <input type="file" id="image" name="image" class="form-control-file">
            </div>
            <br>

            <input class="btn btn-success btn-lg btn-block" type="submit" value="Add Portfolio">
    {!! Form::close() !!}

脚本:

<script>
    CKEDITOR.replace( 'content' );
</script>

enter image description here

1 个答案:

答案 0 :(得分:0)

我可以从CKEditor的角度解释它的工作原理。

请参阅:https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR.html#cfg-replaceClasshttp://nightly.ckeditor.com/18-09-06-06-04/full/samples/old/replacebyclass.html

CKEditor将替换多个文本区域,前提是它们分配了一个特定的CSS类(默认为ckeditor)。您所需要做的就是将CKEditor脚本附加到HTML文档的标头部分,然后添加一堆<textarea class="ckeditor" name="editor1"></textarea>元素。它们应该自动更改为编辑器。

或者,您可以使用随机的textarea生成id's个元素,收集这些id's,然后使用循环中的replace使用id方法循环运行document.querySelector('#idtest').addEventListener('click', function(){})方法迭代步骤。