Update MarketForm

* use textarea
* add end date input
* add cancel button
* add missing Content-type header
This commit is contained in:
ekzyis 2023-11-20 00:52:21 +01:00
parent bf0e0fea69
commit 0e587d48ca
2 changed files with 18 additions and 10 deletions

View File

@ -1,28 +1,36 @@
<template>
<form ref="form" class="mx-auto text-left" method="post" action="/api/market" @submit.prevent="submitForm">
<label class="mx-1" for="desc">description</label>
<input v-model="description" class="mx-1" id="desc" name="desc" type="text" placeholder="event description">
<button class="mx-1" type="submit">submit</button>
<form ref="form" class="flex flex-col mx-auto text-left" method="post" action="/api/market"
@submit.prevent="submitForm">
<label for="desc">event description</label>
<textarea v-model="description" class="mb-1" id="desc" name="desc" type="text"></textarea>
<label for="endDate">end date</label>
<input v-model="endDate" class="mb-3" id="endDate" name="endDate" type="date" />
<div class="flex flex-row justify-center">
<button type="button" class="me-1" @click.prevent="$props.onCancel">cancel</button>
<button type="submit">submit</button>
</div>
</form>
</template>
<script setup>
import { ref } from 'vue'
import { ref, defineProps } from 'vue'
defineProps(['onCancel'])
const form = ref(null)
const description = ref(null)
const endDate = ref(null)
const submitForm = async () => {
const url = window.origin + '/api/market'
const body = JSON.stringify({ description: description.value })
await fetch(url, { method: 'post', body })
const body = JSON.stringify({ description: description.value, endDate: endDate.value })
await fetch(url, { method: 'post', headers: { 'Content-type': 'application/json' }, body })
}
</script>
<style scoped>
input {
padding: 0 0.3em;
textarea {
color: #000;
}
</style>

View File

@ -6,7 +6,7 @@
</ul>
<button v-if="!showForm" @click.prevent="toggleForm">+ create market</button>
<div v-else class="flex flex-col justify-center">
<MarketForm />
<MarketForm :onCancel="toggleForm" />
</div>
</template>