2016-10-22 64 views
-1

我正在尋找一種方法將quill.js集成到我的站點中,但他們提供的支持不存在或清除爲泥漿。有人能幫我嗎?quill.js與laravel 5.3論壇站點的集成

下面是我的代碼,所有目前內聯,以便更容易看到的一切。我已經設法讓羽毛筆在頁面上運行,並且我可以用它編輯文本,但是當我提交表單時,它不會提交編輯器的值,因爲它應該是...

編輯器應該傳遞它的內容到一個隱藏的輸入並提交它的內容,但是當我提交表單的輸入不填充。

如果有人知道我做錯了什麼,那麼我全都是耳朵,如果有人有更好的方法來嘗試這個問題,那麼我再次建議(順便說一句,表單目前設置爲GET,所以我可以輕鬆地檢查什麼被通過,但已經寫控制器處理的變量是POST-ED。

<div class="row" style="margin-right: 0px; margin-left: 0px;"> 
<div class="col-md-6 col-md-offset-3"> 

    <!-- Title and First Post --> 
    <div class="jumbotron"> 

     <form method="get" action="/forum/create_post" id="create_post"> 
      @if (count($errors)) 
      <div style="padding: 10px;"> 
      <div class="container-fluid" style="background-color: white; padding: 10px;"> 
      <ul> 
       @foreach ($errors->all() as $error) 
        <li>{{ $error }}</li> 
       @endforeach 
      </ul> 
      </div> 
      </div> 
      @endif 
      {{ csrf_field() }} 
      <div style="padding: 10px;"> 
      <div class="container-fluid" style="background-color: white; padding: 10px;"> 
      <input name="title" type="hidden"> 
      <div id="editor-title">{{ old('title') }}</div> 
      </div> 
     </div> 
       <!--<h1><label for="Title">Title</label></h1> 
       <input class="form-control" name="title" type="text" placeholder="Your Title Here..."> 
      <h1><label for="body">Content</label></h1>--> 
      <div style="padding: 10px;"> 
      <div class="container-fluid" style="background-color: white; padding: 10px;"> 
      <input name="body" type="hidden"> 
      <div id="editor-body">{{ old('body') }}</div> 
      </div> 
     </div> 
      <button class="btn btn-primary" type="submit">Save Profile</button> 
     </form> 
    </div> 
    </div> 
</div> 

<script type="text/javascript"> 
var bodyquill = new Quill('#editor-body', { 
modules: { 
    toolbar: [ 
    ['bold', 'italic', 'underline'], 
    ['link', 'blockquote', 'code-block', 'image'], 
    [{ list: 'ordered' }, { list: 'bullet' }] 
    ] 
}, 
placeholder: 'Compose an epic post...', 
theme: 'snow' 
}); 
var titlequill = new Quill('#editor-title', { 
modules: { 
}, 
placeholder: 'Title Here...', 
theme: 'bubble' 
}); 

var form = document.querySelector('form'); 
form.onsubmit = function() { 
var title = document.querySelector('input[name=title]'); 
    title.value = JSON.stringify(titlequill.getContents()); 

var body = document.querySelector('input[name=body]'); 
    body.value = JSON.stringify(bodyquill.getContents()); 

    console.log("Submitted", $(form).serialize(), $(form).serializeArray()); 
// No back end to actually submit to! 
alert('Open the console to see the submit data!') 
return false; 
}; 
</script> 

謝謝!

回答

0

更新原來​​我是比較粗,方法我使用的正文插入身體輸入與保護字衝突,重新編寫代碼以省略任何此類衝突