【问题标题】:Text not storing from summernote in Laravel文本未从 Laravel 中的 Summernote 存储
【发布时间】:2016-11-28 16:38:25
【问题描述】:

我想将summernote (summernote.org) 整合到一个文本区域并保存在数据库中。

我的查看代码:

<div class="col-lg-3"><label>Estado</label>
<textarea name="textfield4" id="textfield4"></textarea></div>
 <button type="submit" class="btn btn-success">Save</button>
<input type="hidden" value="{{Session::token()}}" name="_token">

我的js代码:

              <script>
           $('#textfield4').summernote({

            height:200
           });
             </script>

【问题讨论】:

    标签: javascript jquery laravel laravel-5.2 summernote


    【解决方案1】:

    您应该在 .ready() 函数中编写代码

    $(document).ready(function() {
      $('#textfield4').summernote();
    });
    

    【讨论】:

    【解决方案2】:

    在您提交表单之前,您必须使用 div 来呈现夏季,并使用夏季注释内容填充隐藏的文本区域,请参见下面的示例,

    <div class="panel-body no-padding">
                    <textarea  style="display: none;" name="emailmessage" id="emailmessage"></textarea>
                    <div class="editor-summernote" id="emailmessage_editor"></div>
                </div>
    

    然后将 div 转换为如下所示的夏季笔记编辑器

    $('.editor-summernote').summernote({
                toolbar: [
                    ['headline', ['style']],
                    ['style', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']],
                    ['textsize', ['fontsize']],
                    ['alignment', ['ul', 'ol', 'paragraph', 'lineheight']],
                ],
                height: 120
            });
    

    在提交表单进行服务器端处理之前,使用 jquery 将夏季笔记内容填充到隐藏的文本区域,

       $("#btn-send-message").on("click",function(event) {
    
                var email_body = $('#emailmessage_editor').code();
                $("#emailmessage").html(email_body); //populate text area
       });
    

    最后你可以通过$request-&gt;input('emailmessage')在你的laravel控制器中获取数据

    【讨论】:

    【解决方案3】:

    如果它不起作用,请写下错误消息是什么,我已经修改了你的 javascript 代码,用实际的表单 ID 替换 yourformid 并尝试,我假设你有一个在 html 中定义了动作的表单,

    $(function(){
    
    $('#estado').summernote(
    {
    
      toolbar: [
                    ['headline', ['style']],
                    ['style', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']],
                    ['textsize', ['fontsize']],
                    ['alignment', ['ul', 'ol', 'paragraph', 'lineheight']],
                ],
    
    height:120
    });
    
    $("#yourformid").submit(function(e) {
         var self = this;
         e.preventDefault();
    
         var estado = $('#estado').code();
         $("#textfield4").html(estado); //populate text area
         self.submit();
         return false; 
    });
    });
    

    确保您的令牌被传递或使用以下方法生成令牌,

    <input type="hidden" name="_token" value="{{ csrf_token() 
    

    【讨论】:

    • 我收到以下错误:` Uncaught TypeError: $(...).code is not a function(anonymous function) @ myplace:1565 dispatch @ jquery-1.10.0.min.js :5 v.handle @ jquery-1.10.0.min.js:5`
    • 请在var estado = $('#estado').code();前加上这行代码加上$('#estado').destroy();试试,
    • error : Uncaught TypeError: $(...).destroy is not a function
    • 我认为它的 $('#estado').summernote('destroy');但仍然是同样的错误:未捕获的 TypeError: $(...).code is not a function
    • 尝试将您的夏季笔记版本更改为最新版本,夏季笔记文档中建议的 jquery 版本,
    猜你喜欢
    • 2014-12-09
    • 2018-04-08
    • 2017-01-03
    • 1970-01-01
    • 2021-02-12
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    相关资源
    最近更新 更多