presentations/src/components/SessionForm.vue

73 lines
1.7 KiB
Vue
Raw Normal View History

2019-06-02 23:36:07 +01:00
<template>
<section class="mt-8">
<h3 class="text-2xl font-semibold mb-4">Submit a Session</h3>
<form action="" @submit.prevent="submit">
<label class="block mb-4">
Title
<input name="title" type="text" class="w-full border border-gray-400 p-2 mt-1" v-model="form.title" required/>
</label>
<label class="block mb-4">
Abstract
<textarea name="title" rows="5" class="w-full border border-gray-400 p-2 mt-1" v-model="form.body" required/>
</label>
<input class="cursor-pointer bg-blue-500 hover:bg-blue-700 focus:bg-blue-700 text-gray-100 px-4 py-2 rounded" type="submit" value="Submit session">
</form>
</section>
</template>
<script>
import axios from 'axios'
export default {
data () {
return {
form: {
body: '',
title: '',
2019-06-03 00:54:25 +01:00
field_session_status: 'accepted',
field_session_type: 'full',
2019-06-02 23:36:07 +01:00
}
}
},
methods: {
submit () {
2019-06-03 00:54:25 +01:00
const uuid = '11dad4c2-baa8-4fb2-97c6-12e1ce925806' // User 1
2019-06-02 23:50:01 +01:00
2019-06-03 00:54:25 +01:00
const data = {
type: 'node--session',
attributes: this.form,
relationships: {
"field_speakers": {
"data": {
"type": "user--user",
"id": uuid
}
},
}
}
axios({
method: 'post',
url: 'http://drupaltestcamp.docksal/jsonapi/node/session',
data: { data },
headers: {
'Accept': 'application/vnd.api+json',
'Content-Type': 'application/vnd.api+json',
}
})
.then(({ data }) => {
this.form.body = ''
this.form.title = ''
})
.catch(function (error) {
console.log(error)
});
2019-06-02 23:36:07 +01:00
}
}
}
</script>