samedi 22 octobre 2016

quill.js integration with laravel 5.3 forum site

I am looking for a way to integrate quill.js into my site but the support they give is non-existent or clear as mud. Can someone help me?

Below is my code, all currently inline so to make it easier to see everything. I have managed to get quill to run on the page and i can edit text with it, however when i submit the form it does not submit the values of the editors as it should...

The editor should pass it's contents to a hidden input and submit it's contents however when i am submitting the form the inputs are not populated.

If anyone knows what I am doing wrong then I am all ears, and if someone has a better way to attempt the problem then again I am open to suggestion (btw the form is currently set to GET so i can easily examine what is being passed but the already written controller handles the variables being 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></li>
                @endforeach
            </ul>
            </div>
          </div>
          @endif
          
          <div style="padding: 10px;">
          <div class="container-fluid" style="background-color: white;  padding: 10px;">
          <input name="title" type="hidden">
          <div id="editor-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"></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>

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire