fix select defaut value
This commit is contained in:
@@ -37,7 +37,7 @@ class Event extends JsonResource
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
'links' => [
|
'links' => [
|
||||||
'self' => url('/events/'.$this->id),
|
'self' => $this->path(),
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ class Event extends Model
|
|||||||
{
|
{
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
|
public function path()
|
||||||
|
{
|
||||||
|
return '/events/' . $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
public function category() :BelongsTo
|
public function category() :BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(EventCategory::class, 'category_id');
|
return $this->belongsTo(EventCategory::class, 'category_id');
|
||||||
|
|||||||
@@ -19,12 +19,11 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
date: Date,
|
|
||||||
time: String,
|
|
||||||
required: {
|
required: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
selected: String,
|
||||||
errors: Object,
|
errors: Object,
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
@@ -37,6 +36,12 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
hasError: function () {
|
hasError: function () {
|
||||||
return this.required && this.errors && this.errors[this.name] && this.errors[this.name].length > 0
|
return this.required && this.errors && this.errors[this.name] && this.errors[this.name].length > 0
|
||||||
|
},
|
||||||
|
date: function () {
|
||||||
|
return this.selected.split(' ')[0]
|
||||||
|
},
|
||||||
|
time: function () {
|
||||||
|
return this.selected.split(' ')[1]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="relative mb-2">
|
<div class="relative mb-2">
|
||||||
<label v-if="label" :for="name" class="pb-2 font-bold text-xl ml-1">{{ label }}</label>
|
<label v-if="label" :for="name" class="pb-2 font-bold text-xl ml-1">{{ label }}</label>
|
||||||
<select :name="name" v-for="option in options" :key="option.value" v-model="value" :class="'block w-full p-2 ' + errorClassObject()">
|
<select :name="name"
|
||||||
<option value="">----</option>
|
v-model="selected"
|
||||||
<option :value="option.value" v-if="selected === String(option.value)" selected>{{ option.label }}</option>
|
:class="'block w-full p-2 ' + errorClassObject()">
|
||||||
<option :value="option.value" v-else>{{ option.label }}</option>
|
<option v-for="option in options"
|
||||||
|
:key="option.value"
|
||||||
|
:value="option.value">{{ option.label }}</option>
|
||||||
</select>
|
</select>
|
||||||
<p class="text-red no-indent m-0" v-text="errorMessage()">Error Here</p>
|
<p class="text-red no-indent m-0" v-text="errorMessage()">Error Here</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -21,18 +23,13 @@ export default {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
options: Array,
|
options: Array,
|
||||||
selected: String,
|
selected: Number,
|
||||||
required: {
|
required: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
errors: Object,
|
errors: Object,
|
||||||
},
|
},
|
||||||
data: function () {
|
|
||||||
return {
|
|
||||||
value: ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
hasError: function () {
|
hasError: function () {
|
||||||
return this.required && this.errors && this.errors[this.name] && this.errors[this.name].length > 0
|
return this.required && this.errors && this.errors[this.name] && this.errors[this.name].length > 0
|
||||||
@@ -56,9 +53,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
value: function () {
|
selected: function () {
|
||||||
this.clearErrors(this.name)
|
this.clearErrors(this.name)
|
||||||
this.$emit('update:field', this.value)
|
this.$emit('update:field', this.selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
<DateTimeField
|
<DateTimeField
|
||||||
label="Date de fin"
|
label="Date de fin"
|
||||||
name="end_date"
|
name="end_date"
|
||||||
required />
|
@update:field="form.end_date = $event" :errors="errors" />
|
||||||
</div>
|
</div>
|
||||||
<TextAreaField name="description"
|
<TextAreaField name="description"
|
||||||
label="Description"
|
label="Description"
|
||||||
@@ -91,7 +91,6 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
submitForm: function () {
|
submitForm: function () {
|
||||||
this.form.private = this.checked
|
this.form.private = this.checked
|
||||||
console.log(this.form)
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
axios.post('/api/events', this.form)
|
axios.post('/api/events', this.form)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<form v-else @submit.prevent="submitForm">
|
<form v-else @submit.prevent="submitForm">
|
||||||
<div class="flex justify-between flex-center mb-4">
|
<div class="flex justify-between flex-center mb-4">
|
||||||
<router-link to="/memos/" class="btn">Back</router-link>
|
<router-link to="/memos/" class="btn">Back</router-link>
|
||||||
<button class="btn-primary">Add New Memo</button>
|
<button type="submit" class="btn-primary">Update Event</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<InputField name="name"
|
<InputField name="name"
|
||||||
@@ -26,22 +26,24 @@
|
|||||||
required
|
required
|
||||||
@update:field="form.location = $event" :errors="errors" />
|
@update:field="form.location = $event" :errors="errors" />
|
||||||
<SelectorField name="category_id"
|
<SelectorField name="category_id"
|
||||||
|
v-if="form.category_id"
|
||||||
label="Catégorie"
|
label="Catégorie"
|
||||||
:options="categories"
|
:options="categories"
|
||||||
class="mr-4"
|
class="mr-4"
|
||||||
required
|
required
|
||||||
:selected="String(form.category_id)"
|
:selected="form.category_id"
|
||||||
@update:field="form.category_id = $event" :errors="errors" />
|
@update:field="form.category_id = $event" :errors="errors" />
|
||||||
<DateTimeField
|
<DateTimeField
|
||||||
class="mr-4"
|
class="mr-4"
|
||||||
label="Date de début"
|
label="Date de début"
|
||||||
name="start_date"
|
name="start_date"
|
||||||
|
:selected="form.start_date"
|
||||||
required
|
required
|
||||||
@update:field="form.start_date = $event" :errors="errors" />
|
@update:field="form.start_date = $event" :errors="errors" />
|
||||||
<DateTimeField
|
<DateTimeField
|
||||||
label="Date de fin"
|
label="Date de fin"
|
||||||
name="end_date"
|
name="end_date"
|
||||||
required />
|
@update:field="form.end_date = $event" :errors="errors" />
|
||||||
</div>
|
</div>
|
||||||
<TextAreaField name="description"
|
<TextAreaField name="description"
|
||||||
label="Description"
|
label="Description"
|
||||||
@@ -103,8 +105,6 @@ export default {
|
|||||||
this.form = this.event.data.attributes.data
|
this.form = this.event.data.attributes.data
|
||||||
this.form.description = this.event.data.attributes.data.description
|
this.form.description = this.event.data.attributes.data.description
|
||||||
this.form.category_id = this.event.data.attributes.data.category.data.event_category_id
|
this.form.category_id = this.event.data.attributes.data.category.data.event_category_id
|
||||||
console.log(this.form)
|
|
||||||
// this.loading = false
|
|
||||||
})
|
})
|
||||||
.catch(errors => {
|
.catch(errors => {
|
||||||
this.errors = errors.response.data.errors
|
this.errors = errors.response.data.errors
|
||||||
@@ -113,10 +113,12 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
submitForm: function () {
|
submitForm: function () {
|
||||||
this.form.private = this.checked
|
this.form.private = this.checked
|
||||||
console.log(this.form)
|
delete this.form.category
|
||||||
|
delete this.form.invitations
|
||||||
|
delete this.form['invitations-with-email']
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
axios.patch('/api/events', this.form)
|
axios.patch('/api/events/' + this.event.data.event_id, this.form)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.$router.push(response.data.links.self)
|
this.$router.push(response.data.links.self)
|
||||||
})
|
})
|
||||||
@@ -127,7 +129,6 @@ export default {
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
checked: function () {
|
checked: function () {
|
||||||
console.log(this.checked, this.form)
|
|
||||||
this.form.private = this.checked
|
this.form.private = this.checked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,15 @@
|
|||||||
<div v-else class="box">
|
<div v-else class="box">
|
||||||
<div class="flex justify-between flex-wrap">
|
<div class="flex justify-between flex-wrap">
|
||||||
<h1 class="text-xl text-marine">{{ event.data.attributes.data.name }}</h1>
|
<h1 class="text-xl text-marine">{{ event.data.attributes.data.name }}</h1>
|
||||||
<h2 class="text-sm text-marine">{{ event.data.attributes.data.location }}</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="event.data.attributes.data.description">{{ event.data.attributes.data.description }}</div>
|
|
||||||
<div class="flex justify-between">
|
|
||||||
<span class="mt-auto self-end bg-gray-400 text-white tag">{{ event.data.attributes.data.category.data.attributes.data.name }}</span>
|
<span class="mt-auto self-end bg-gray-400 text-white tag">{{ event.data.attributes.data.category.data.attributes.data.name }}</span>
|
||||||
<span class="mt-auto self-end bg-gray-400 text-white tag">{{ event.data.attributes.data.start_date }}</span>
|
</div>
|
||||||
|
<h2 class="text-lg text-marine">{{ event.data.attributes.data.location }}</h2>
|
||||||
|
<div v-if="event.data.attributes.data.description">{{ event.data.attributes.data.description }}</div>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<div>
|
||||||
|
<span class="mt-auto self-end bg-gray-400 text-white tag">{{ event.data.attributes.data.start_date }}</span>
|
||||||
|
<span v-if="event.data.attributes.data.end_date" class="mt-auto self-end bg-gray-400 text-white tag">{{ event.data.attributes.data.end_date }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ export default {
|
|||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
axios.post('/api/to-do-lists', {name: this.name})
|
axios.post('/api/to-do-lists', {name: this.name})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res)
|
|
||||||
this.modal = false
|
this.modal = false
|
||||||
this.name = ''
|
this.name = ''
|
||||||
this.toDoLists.push(res.data)
|
this.toDoLists.push(res.data)
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ class EventsTest extends TestCase
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
'links' => [
|
'links' => [
|
||||||
'self' => url('/events/'.$event->id),
|
'self' => '/events/'.$event->id,
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user