F-loat / vue-simplemde

📝 Vue SimpleMDE - use simplemde with vue.js
https://F-loat.github.io/vue-simplemde/dist/demo.html
MIT License
768 stars 111 forks source link

Form POST does not send the textarea data #57

Closed axelitus closed 6 years ago

axelitus commented 6 years ago

I'm using vue-simplemde with Laravel and so far it works great, the only issue is that when I submit the form, no data is passed through the POST action.

I'm really new with Vue so I don't know if I'm doing something wrong, but I think this is because the template contains a textarea without a name attribute, so no data is passed along. I think it would be nice to have a prop that sets the name of the textarea so that it can be set to whatever is expecting the form processing script page. For example:

<markdown-editor :name="my_content"></markdown-editor>

This would render the following code:

<div class="markdown-editor">
    <textarea name="my_content" style="display: none;"></textarea>
    <div class="editor-toolbar"> ... </div>
</div>
axelitus commented 6 years ago

I created my custom markdown editor based on this one, but I think it needs this feature. I've managed to do the following:

<markdown-editor name="content" :value="{{ json_encode($content) }}"></markdown-editor>

I added prop name as String and on the initialize method I added this at the beginning:

if (this.name) {
    this.$el.firstElementChild.setAttribute('name', this.name);
}

I don't know if this is the best way to do this, but it is working.

F-loat commented 6 years ago

If you want to submit directly, please set forceSync to true. SimpleMDE Configuration.

<markdown-editor name="content" :config="{ forceSync: true }"></markdown-editor>

Using v-model to bind data and using ajax method to send is the normal way.

axelitus commented 6 years ago

It does not work for me. I'm doing this:

<markdown-editor name="content" :config="{ forceSync: true }" :value="{{ json_encode($content) }}"></markdown-editor>

When saving the form (via post request), the content is never sent.

F-loat commented 6 years ago

Sorry, it should be configs and please update to 0.4.9 for the name prop support.

<markdown-editor name="content" :configs="{ forceSync: true }" :value="{{ json_encode($content) }}"></markdown-editor>