Hello,
Just as an exercise, Iām trying to make a WYSIWYG system using Kirby and Vue.js. The front-end edition system works : I can click on a text, it turns into a field containing the text, I clicked on, then I can edit it, click on submit then the field turns into a solid text corresponding to the text written in the field.
I added a final submit button that posts (POST method) all the edited data. I wonder how to pass it to the data of the page. Iām almost ignorant concerning controllers. Here is what I tried :
Template :
<div id="app-wysiwyg">
<p @click="toggleEdit"> {{ message }} </p>
<div id="edit">
<input type="textarea" v-model="message">
<input type="submit" value="Ok" @click="toggleEdit">
</div>
<form action="<?= $page->url() ?>" method="post">
<input name="message" type="textarea" v-model="message" style="display: none;">
<input type="submit" value="Valider" @click="toggleEdit">
</form>
</div>
Controller :
<?php
return function ($page) {
$page->message() = $_POST['message'];
return $page->message();
};
Vue :
new Vue({
el: '#app-wysiwyg',
data: {
message: 'Ceci est un paragraphe modifiable, cliquez dessus pour essayer.',
contentHide: {},
},
methods: {
toggleEdit: function(e) {
if (e.target.tagName !== 'INPUT') {
this.contentHide = e.target
console.log(this.contentHide.tagName)
let contentWidth = this.contentHide.offsetWidth
this.contentHide.style.display = "none"
let edit = document.getElementById('edit')
edit.style.display = "block"
edit.firstChild.style.width = contentWidth + "px"
} else {
document.getElementById('edit').style.display = "none"
this.contentHide.style.display = "block"
this.contentHide = {}
}
}
}
})
CSS :
#edit {
display: none;
}
Thanks for your help.