Files
app/src/components/aircrafts/AircraftForm.vue
T

84 lines
1.9 KiB
Vue

<script setup>
import {onMounted, reactive} from "vue";
import FormWrapper from "components/FormWrapper.vue";
import {setDefaultData} from "src/composables/form/formHandling";
import {defaultValues, isRequestPending} from "src/composables/form/props";
import {isNumber, isRequired, maxLength, minLength} from "src/composables/form/rules";
import {commonProps} from "src/composables/inputs";
const formData = reactive({
id: null,
callSign: "",
model: "",
seats: null,
manufacturer: "",
description: "",
photo: null,
organizationId: null
});
const props = defineProps({
defaultValues,
isRequestPending
});
const rules = {
callSign: [isRequired, minLength(4), maxLength(8)],
seats: [isRequired, isNumber]
};
onMounted(() => {
if (Object.keys(props.defaultValues).length > 0)
setDefaultData(formData, props.defaultValues);
})
</script>
<template>
<FormWrapper v-model="formData" :is-request-pending="props.isRequestPending">
<q-img :src="props.defaultValues.photoUrl" v-if="props.defaultValues.photoUrl"/>
<q-input
type="text"
:rules="rules.callSign"
v-model="formData.callSign"
label="Volací značka"
v-bind="commonProps"
/>
<q-input
type="text"
v-model="formData.manufacturer"
label="Výrobce"
v-bind="commonProps"
/>
<q-input
type="text"
v-model="formData.model"
label="Model"
v-bind="commonProps"
/>
<q-input
type="number"
v-model.number="formData.seats"
label="Počet míst (včetně pilota)"
min="1"
:rules="rules.seats"
v-bind="commonProps"
/>
<q-input
type="textarea"
v-model="formData.description"
label="Popis"
v-bind="commonProps"
/>
<q-file v-model="formData.photo" label="Fotografie" v-bind="commonProps">
<template #prepend>
<q-icon name="upload"/>
</template>
</q-file>
</FormWrapper>
</template>