We have a editPage.vue to save page data. It works really well.. But when we check a page as home and later on edit that page and click on done to save the checkbox to make that page home is removed. We then have to click on edit page again, check the checkbox and save again.
Current checkbox and save page part is this:
...
<input type="checkbox" name="homepage" v-model="page.homepage" @change="checkHomePage" style="vertical-align:sub;" />
<button class="btn btn-primary pull-right" :disabled="!isSlugValid || disabled" @click="savePage">done</button>
...
relevant JS in script to check for home and save page is this:
data() {
return {
page: null,
grids: [],
isSlugValid: true,
parentPage: '',
isCloning: false,
}
},
...
checkHomePage() {
if (this.page.homepage) return;
for(let i = 0; i < this.pages.length; i++) {
if (this.pages[i].homepage && this.pages[i].id != this.page.id) return;
}
// Don't have any homepage set current page is homepage
alert('At least one page needs to be checked as home for proper display')
},
...
savePage() {
this.page.parent_id = this.parentPage ? this.parentPage.id : null
if (this.isCloning) {
let pages = this.$store.getters['editor/pages'] || []
if (pages && pages.length > 0 && pages.some(page => page.name === this.page.name || page.slug === this.page.slug)) {
EventBus.$emit('showError', {message: 'unique page name and slug required'});
return
}
}
let path = this.isCloning ? '/editor/clone-page/' : '/editor/update-page/'
axios.patch(path + this.page.id + `?project=${PROJECT_ID}`, { page: this.page })
.then(this.handleSaveResponse)
.catch((err) => {
if (err.data.errors) {
EventBus.$emit('showError', err.data.errors[Object.keys(err.data.errors)[0]][0])
}
})
},
...
On clicking done
public function updatePage(UpdateRequest $request, Page $page)
{
try {
$postPage = (object) $request->input('page');
if ($postPage->homepage) {
Page::clearHomePage($this->currentProject->id);
}
$page->json = json_encode($postPage);
$page->name = $postPage->name;
$page->grid_id = $postPage->gridId;
$page->homepage = $postPage->homepage;
$page->slug = $postPage->slug;
$page->save();
} catch (\Exception $e) {
return $this->respondFailedWithError(500, $e->getMessage());
}
return $this->respondWithSuccess(200, new PageResource($page));
}
is fired.
Any idea why the homepage checkbox is unchecked on opening this edit modal and clicking done? And how to avoid this?