VueJS how to rerender a component - vue.js

I have a VueJS component which populates a table via ajax, than I have a modal form inside component which creates new entries in table.
On modal hide I want to update the table to show new entries.
export default {
created() {
axios.get('/api/v1/customers')
.then(response => {
this.customers = response.data;
});
},
methods: {
store() {
this.form.errors = [];
axios.post('/api/v1/customers', this.form)
.then(response => {
this.form.name = '';
this.form.scopes = [];
this.form.errors = [];
$('#modal-edit-client').modal('hide');
this.$forceUpdate();
})
.catch(error => {
console.log(error)
/*if (typeof error.response.data === 'object') {
this.form.errors = _.flatten(_.toArray(error.response.data));
} else {
this.form.errors = ['Something went wrong. Please try again.'];
}*/
});
},
newUser: function () {
$('#modal-edit-client').modal('show');
},
edit: function () {
alert('edit modal')
}
},
data() {
return {
customers: {},
alert: {
show: false,
type: null,
title: null,
message: null,
},
form: {
scopes: [],
errors: []
}
};
}
}
I tried to use $forceUpdate() but does not seems to work
output template
<template>
<div class="row" v-cloak>
<div class="col-md-12 ">
<div class="panel panel-default custom-panel">
<div class="panel-heading">
<strong>Customers</strong>
<div id="custom-search-input">
<div class="input-group col-md-12">
<input v-on:keyup.enter="filter" type="text" class="form-control input-sm" placeholder="Search Customer" />
<span class="input-group-btn">
<button class="btn btn-info btn-lg" type="button">
<i class="glyphicon glyphicon-search"></i>
</button>
</span>
</div>
</div>
<a class="btn icon-btn btn-success" id="new__item" href="#" #click="newUser">
<span class="glyphicon btn-glyphicon glyphicon-plus img-circle text-success"></span> Add Customer
</a>
</div>
<div class="panel-body">
<table class="table table-condensed">
<tbody>
<tr>
<th style="width: 10px">#</th>
<th>Firma</th>
<th>Strasse</th>
<th>PLZ</th>
<th>Ort</th>
<th>Tel</th>
<th>Status</th>
<th>Actions</th>
</tr>
<tr v-for="customer in customers">
<td>{{ customer.id }}</td>
<td>{{ customer.customer_name }}</td>
<td>{{ customer.customer_street }}</td>
<td>{{ customer.customer_plz }}</td>
<td>{{ customer.customer_city }}</td>
<td>{{ customer.customer_telephone }}</td>
<td><span class="badge bg-green"><i class="fa fa-check"></i></span></td>
<td class="actions">
<i class="fa fa-pencil"></i>
<i class="fa fa-trash"></i>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- Edit Client Modal -->
<div class="modal fade" id="modal-edit-client" tabindex="-1" role="dialog">
<div class="spinner"></div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button " class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
Add Customer
</h4>
</div>
<div class="modal-body">
<!-- Form Errors -->
<!--<div class="alert alert-danger" v-if="alert" >
<p><strong>Whoops!</strong> Something went wrong!</p>
<br>
</div>-->
<!-- Edit Client Form -->
<form class="form-horizontal" id="modal-create-customer" role="form" method="POST" action="">
<div class="row">
<div class="col-xs-12">
<label for="customer_name" class="control-label">Firmenbezeichnung</label>
<input id="customer_name" type="text" class="form-control" v-model="form.customer_name" name="customer_name" value="" required autofocus>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="sex" class="control-label">Anrede</label>
<select v-model="form.customer_contact_sex" name="title" id="sex" class="form-control">
<option value="Herr">Herr</option>
<option value="Frau">Frau</option>
</select>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="title" class="control-label">Title</label>
<select v-model="form.customer_contact_title" name="title" id="title" class="form-control">
<option value="">No title</option>
<option value="Dr.">Dr.</option>
<option value="Prof.">Prof.</option>
</select>
<span class="help-block">
<strong></strong>
</span>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<label for="name" class="control-label">First Name</label>
<input id="name" type="text" class="form-control" v-model="form.customer_first_name" name="customer_name" value="" required autofocus>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="email" class="control-label">Last Name</label>
<input id="email" type="text" class="form-control" v-model="form.customer_last_name" name="customer_last_name" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="street" class="control-label">Street</label>
<input id="street" type="text" class="form-control" v-model="form.customer_street" name="customer_street" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-2">
<label for="plz" class="control-label">PLZ</label>
<input id="plz" type="text" class="form-control" v-model="form.customer_plz" name="customer_plz" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-4">
<label for="city" class="control-label">City</label>
<input id="city" type="text" class="form-control" v-model="form.customer_city" name="customer_city" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="customer_telephone" class="control-label">Tel.</label>
<input id="customer_telephone" type="text" class="form-control" v-model="form.customer_telephone" name="customer_telephone" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="customer_fax" class="control-label">Fax.</label>
<input id="customer_fax" type="text" class="form-control" name="customer_fax" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="customer_mobile" class="control-label">Mobil</label>
<input id="customer_mobile" type="text" class="form-control" name="customer_mobile" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-6">
<label for="customer_email" class="control-label">E-Mail.</label>
<input id="customer_email" type="text" class="form-control" name="customer_email" value="" required>
<span class="help-block">
<strong></strong>
</span>
</div>
<div class="col-xs-12">
<label for="customer_note" class="control-label">Notiz</label>
<textarea name="csutomer_note" id="customer_note" class="form-control"></textarea>
<span class="help-block">
<strong></strong>
</span>
</div>
</div>
</form>
</div>
<!-- Modal Actions -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" #click="store">
Register
</button>
</div>
</div>
</div>
</div>
</div>
</template>

As said in the comments, your code looks fine except that you're not actually updating the customers property with anything.
When you're performing the XHR request with Axios, you need to use the response to populate the component, which will automatically update the relevant DOM.
Here is the relevant part of your code that you should modify:
axios.post('/api/v1/customers', this.form)
.then(response => {
this.form.name = '';
this.form.scopes = [];
this.form.errors = [];
// Set the component's customers property to what you get
// in the response
this.customers = response.data.customers;
$('#modal-edit-client').modal('hide');
// You don't need to forceUpdate as Vue will take care of
// rerendering the relevant parts of the DOM
// this.$forceUpdate();
})
Also, considering you're expecting an array of customers to render the table, you should set the customers default value accordingly:
data() {
return {
customers: []
// ...
};
}

Related

Correct bootstrap3 way to give padding on grid

I have four inputs in the same row and one of the input is conditionally visible by clicking "Click" button.
So if all four inputs are visible, the inputs datepicker1 and datepicker2 are sticked on the inputs above.
What is the correct bootstrap way to arrange and beautify the distances between the inputs?.
Gutters are not available on bootstrap 3.
<div class="col-md-3">
<select class="lookup-type-select form-control" name="created_lookup_type_1">
<option value="range">Range</option>
<option value="range__exclude">Exclude Range</option>
</select>
</div>
<div class="lookup-value">
<div class="col-md-3">
<select name="created__1_0" class="filter-input shortcut form-control" id="id_created__1_0">
</select>
</div>
<div class="col-md-8 row custom" style="display: inline;">
<div class="col-md-6">
<div class="datetimepicker input-group start-date date" data-date-format="YYYY-MM-DD HH:mm:ss">
<input class="filter-input form-control" name="created__1_1" value="" type="text" id="datepicker1" placeholder="From">
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon"></span>
</span>
</div>
</div>
<div class="col-md-6">
<div class="datetimepicker input-group end-date date" data-date-format="YYYY-MM-DD HH:mm:ss">
<input class="filter-input form-control" name="created__1_2" value="" type="text" id="datepicker2" placeholder="To">
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon"></span>
</span>
</div>
</div>
</div>
<div class="col-md-3 row month_only" style="display: none;">
<div>
<div class="datetimepicker input-group start-date date month_only" style="display: none;">
<input class="filter-input form-control" name="created__1_3" value="" type="text" id="id_created__1_3" placeholder="Month">
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon"></span>
</span>
</div>
</div>
</div>
</div>
<button type="button" class="btn remove-button">
<span class="glyphicon glyphicon-remove"></span>
</button>
<button onclick="myFunction()">Ckick</button>
<script>
function myFunction() {
if (document.getElementById('id_created__1_0').style.display != "none") {
document.getElementById("id_created__1_0").style.display = "none";
} else {
document.getElementById("id_created__1_0").style.display = "inline";
}
}
</script>
Jsfiddle example
Should be like the following pic

laravel 9 vue 3 edit multiple checked checkbox value

when editing a checkbox array, I cannot select (checked) that are in the database
how to select those that exist in the checkbox database (checked) ?
please, help
Edit.vue
<template>
<div>
<admin-layout>
<template #header>
<div class="row">
<div class="col-md-12">
<h4>Емделуші</h4>
</div>
</div>
</template>
<div class="row">
<div class="col-md-12 mb-3">
<div class="card">
<div class="card-header">
<span><i class="bi bi-table me-2"></i></span> Емделушіні өзгерту
<div class="card-header-pills float-end">
<inertia-link :href="route('admin.schedules.index')" class="btn btn-primary text-white text-uppercase" style="letter-spacing: 0.1em;">
Кері қайту
</inertia-link>
</div>
</div>
<form #submit.prevent="updateSchedule">
<div class="card-body">
<div class="mb-3">
<label for="name" class="form-label">Аты-жөні</label>
<input type="text" class="form-control" id="name" v-model="form.name" :class="{'is-invalid' : form.errors.name }" autofocus="autofocus" autocomplete="off">
</div>
<div class="invalid-feedback mb-3" :class="{ 'd-block' : form.errors.name }">
{{ form.errors.name }}
</div>
<div class="mb-3">
<label class="form-label" for="email">Email</label>
<input type="text" class="form-control" id="email" v-model="form.email" :class="{'is-invalid' : form.errors.email }" autofocus="autofocus" autocomplete="off">
</div>
<div class="invalid-feedback mb-3" :class="{ 'd-block' : form.errors.email }">
{{ form.errors.email }}
</div>
<div class="mb-3">
<label class="form-label" for="phone">Телефон</label>
<input type="text" class="form-control" id="phone" v-model="form.phone" :class="{'is-invalid' : form.errors.phone }" autofocus="autofocus" autocomplete="off">
</div>
<div class="invalid-feedback mb-3" :class="{ 'd-block' : form.errors.phone }">
{{ form.errors.phone }}
</div>
<div class="form-check form-check-inline" v-for="(time, index) in times" :key="index">
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" :value="time.time" v-model="form.times" :class="{'is-invalid' : form.errors.times }">
<label class="form-check-label" for="inlineCheckbox1">{{ time.time }}</label>
</div>
<div class="invalid-feedback mb-3" :class="{ 'd-block' : form.errors.times }">
{{ form.errors.times }}
</div>
</div>
<div class="card-footer clearfix">
<div class="float-end">
<jet-button class="ms-4 btn-primary text-white" :class="{ 'text-white-50': form.processing }" :disabled="form.processing">
<div v-show="form.processing" class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Өзгертілуде...</span>
</div>
Өзгерту
</jet-button>
</div>
</div>
</form>
</div>
</div>
</div>
</admin-layout>
</div>
</template>
<script>
import AdminLayout from '#/Layouts/AdminLayout';
import JetButton from '#/Jetstream/Button.vue'
import { useForm } from '#inertiajs/inertia-vue3';
import InertiaLink from "#inertiajs/inertia-vue3/src/link";
export default {
name: "Edit",
components: {
AdminLayout,
JetButton,
InertiaLink,
},
props: {
appointment: {},
times: {},
},
setup (props) {
const form = useForm({
name: props.appointment.name,
email: props.appointment.email,
phone: props.appointment.phone,
times: props.times,
});
return {
form,
}
},
methods: {
},
}
}
</script>
when editing a checkbox array, I cannot select (checked) that are in the database how to select those that exist in the checkbox database (checked) ? please, help

Uncaught TypeError: _ctx. is not a function [VueJS 3]

I have problems when I put all my buttons inside one component and use click event to trigger the modals, I can put single button to single component and use event click with created custom components but I am questioning is there any way to put all buttons inside a components and that still works.
Buttons.vue
<template>
<button
class="btn btn-link btn-info btn-icon btn-sm"
data-toggle="modal" data-target="#userInfoModal"
#click="getUserInfo(user)">
<i class="icon-alert-circle-exc"></i>
</button>
<button
class="btn btn-link btn-warning btn-icon btn-sm"
data-toggle="modal" data-target="#userEditModal"
#click="getUserInfo(user)">
<i class="icon-pencil"></i>
</button>
<button
class="btn btn-link btn-danger btn-icon btn-sm"
data-toggle="modal" data-target="#userRemoveModal"
#click="getUserInfo(user)">
<i class="icon-simple-remove"></i>
</button>
</template>
usersManage.vue
<template>
<div class="col-md-12">
<div class="card">
<div class="card-header d-flex flex-row">
<h4 class="card-title align-self-center">Users Manager</h4>
<button class="btn btn-success btn-fab btn-icon btn-round mb-3 ml-2"
data-toggle="modal" data-target="#addUserModal">
<i class="icon-add"></i>
</button>
</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Email</th>
<th>Username</th>
<th class="text-right">Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="(user, id) in users" :key="user.id">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>{{ user.username }}</td>
<td class="text-right">
<!--- BUTTON COMPONENT HERE --->
<Buttons />
<!--- END BUTTON COMPONENT --->
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- MODALS -->
<!-- ADD USER MODAL -->
<div
class="modal modal-black fade" id="addUserModal"
tabindex="-1" role="dialog" aria-labelledby="addUserModal" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="addUserModal">Add new user</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="tim-icons icon-simple-remove"></i>
</button>
</div>
<form class="form-horizontal">
<div class="modal-body">
<div class="d-flex flex-row">
<label class="col-md-4 col-form-label">Name</label>
<div class="col-md-6">
<div class="form-group">
<input
type="name"
name="name"
class="form-control"
v-model="newUser.name"
/>
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-4 col-form-label">Username</label>
<div class="col-md-6">
<div class="form-group">
<input type="username" name="username" class="form-control"
v-model="newUser.username" />
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-4 col-form-label">Email</label>
<div class="col-md-6">
<div class="form-group">
<input type="email" name="email" class="form-control"
v-model="newUser.email" />
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-4 col-form-label">Password</label>
<div class="col-md-6">
<div class="form-group">
<input type="password" name="password" class="form-control"
v-model="newUser.password" />
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-4 col-form-label">Confirm Password</label>
<div class="col-md-6">
<div class="form-group">
<input type="password" name="confirmPassword" class="form-control"
v-model="newUser.confirmPassword" />
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-4 col-form-label">Roles</label>
<div class="col-md-6">
<div class="form-group">
<input type="roles" name="roles" class="form-control"
v-model="newUser.roles" />
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button type="submit" class="btn btn-primary" #click.stop.prevent="addUser()">
Create user
</button>
</div>
</form>
</div>
</div>
</div>
<!-- END ADD USER MODAL -->
<!-- USER's INFO MODAL -->
<div class="modal modal-black fade" id="userInfoModal"
tabindex="-1" role="dialog" aria-labelledby="userInfoModal" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="userInfoModal">
<strong class="text-primary">
{{ userInfo.username }} - {{ userInfo.name }}
</strong>'s Basic Information
</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="tim-icons icon-simple-remove"></i>
</button>
</div>
<div class="modal-body" id="userInfo">
<div class="row">
<div class="col-6">
<p>ID: {{ userInfo.id }}</p>
<p>Phone: {{ userInfo.phone }}</p>
<p>Username: {{ userInfo.username }}</p>
</div>
<div class="col-6">
<p>Name: {{ userInfo.name }}</p>
<p>Email: {{ userInfo.email }}</p>
</div>
</div>
</div>
<div class="modal-footer d-flex flex-row-reverse">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<!-- END USER's INFO MODAL -->
<!-- EDIT USER MODAL -->
<div class="modal modal-black fade" id="userEditModal"
tabindex="-1" role="dialog" aria-labelledby="userEditModal" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="userEditModal">
Edit user
<strong class="text-primary">
{{ userInfo.name }} - {{ userInfo.username }}
</strong>
</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="tim-icons icon-simple-remove"></i>
</button>
</div>
<form class="form-horizontal" method="PUT">
<div class="modal-body">
<div class="d-flex flex-row">
<label class="col-md-3 col-form-label">Username</label>
<div class="col-md-9">
<div class="form-group">
<input type="text" class="form-control" name="username"
v-model="userInfo.username" />
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-3 col-form-label">Name</label>
<div class="col-md-9">
<div class="form-group">
<input type="text" class="form-control" name="username"
v-model="userInfo.name" />
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-3 col-form-label">Email</label>
<div class="col-md-9">
<div class="form-group">
<input type="email" name="email" class="form-control"
v-model="userInfo.email" />
</div>
</div>
</div>
<div class="d-flex flex-row">
<label class="col-md-3 col-form-label">Roles</label>
<div class="col-md-9">
<div class="form-group">
<input type="roles" name="roles" class="form-control"
v-model="userInfo.roles" />
</div>
</div>
</div>
</div>
<div class="modal-footer d-flex flex-row">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Close
</button>
<button type="submit" class="btn btn-primary" data-dismiss="modal"
#click="updateUser()">
Save Changes
</button>
</div>
</form>
</div>
</div>
</div>
<!-- END EDIT USER MODAL -->
<!-- REMOVE USER MODAL -->
<div class="modal modal-black fade" id="userRemoveModal"
tabindex="-1" role="dialog" aria-labelledby="userRemoveModal" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="userRemoveModal">
Confirm delete user
<strong class="text-primary">
{{ userInfo.username }} - {{ userInfo.name }}
</strong>?
</h4>
<button
type="button"
class="close"
data-dismiss="modal"
aria-hidden="true"
>
<i class="tim-icons icon-simple-remove"></i>
</button>
</div>
<div class="modal-body h4 text-white text-center mt-4">
Delete user
<strong class="text-danger">
{{ userInfo.username }} - {{ userInfo.name }}
</strong>
?
</div>
<div class="modal-footer d-flex flex-row">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
Cancel
</button>
<button type="button" class="btn btn-danger" data-dismiss="modal"
#click="removeUser()">
Delete User
</button>
</div>
</div>
</div>
</div>
<!-- END REMOVE USER MODAL -->
<!-- END MODALS -->
</template>
<script>
import axios from "axios";
import InfoButton from ".../components/cores/Buttons.vue";
const API_URL = "http://localhost:8000/api";
export default {
name: "manageUsers",
components: { InfoButton },
data() {
return {
users: [],
newUser: {
name: null,
username: null,
email: null,
password: null,
confirmPassword: null,
roles: null,
},
userInfo: {
id: 0,
name: "",
username: "",
phone: "",
email: "",
password: "",
},
};
},
methods: {
refreshUsers() {
axios.get(`${API_URL}/users/allusers`).then((res) => {
this.users = res.data.data;
});
},
addUser() {
axios
.post(`${API_URL}/users/create`, this.newUser)
.then((res) => {})
.catch((error) => {
console.log("ERRRR:: ", error.response.data);
});
this.$router.push("/manager/users");
},
getUserInfo(user) {
axios
.get(`${API_URL}/users/show/` + user.id)
.then((res) => {
this.userInfo.id = res.data.data.id;
this.userInfo.name = res.data.data.name;
this.userInfo.email = res.data.data.email;
this.userInfo.username = res.data.data.username;
this.userInfo.phone = res.data.data.phone;
})
.catch((error) => {
console.log("ERRRR:: ", error.response.data);
});
},
updateUser() {
axios
.put(`${API_URL}/users/update/${this.userInfo.id}`, {
name: this.userInfo.name,
username: this.userInfo.username,
email: this.userInfo.email,
password: null,
roles: this.userInfo.roles,
})
.then((res) => {
this.refreshUsers();
})
.catch((error) => {
console.log("ERRRR:: ", error.response.data);
});
},
removeUser() {
axios
.delete(`${API_URL}/users/delete/${this.userInfo.id}`)
.then((res) => {
this.refreshUsers();
})
.catch((error) => {
console.log("ERRRR:: ", error.response.data);
});
},
},
mounted() {
this.refreshUsers();
},
};
</script>
I had the same problem and the solution was to send each button to a different function

How to listen to events from bootstrap-vue modal?

I have two modals in my page and I need a way to listen to 'ok' event when pressing ok button on first modal and respond by opening the another modal.
There are no examples in the documentation:
https://bootstrap-vue.js.org/docs/components/modal/
I wanted to use this listener but nothing is explained and I couldn't find out what is what here.
export default {
mounted() {
this.$root.$on('bv::modal::show', (bvEvent, modalId) => {
console.log('Modal is about to be shown', bvEvent, modalId)
})
}
}
This is the relevant part of my code:
<div>
<b-modal id="modal-center-add-post" style="width: 120px" centered class="h-50 d-inline-block min-vw-100" ok-title="next" >
<add-post></add-post>
</b-modal>
</div>
<div>
<b-modal id="modal-center-add-content" style="width: 120px"
centered class="h-50 d-inline-block min-vw-100"
ok-only ok-title="Create" >
<add-content></add-content>
</b-modal>
</div>
and add-post component code is
<template>
<form>
<div class="form-group row">
<label for="title"
class="col-sm-2 col-form-label">
Title
</label>
<div class="col-sm-10">
<input type="text"
class="form-control"
id="title"
placeholder="Title">
</div>
</div>
<div class="form-group row">
<label for="chooseTopic"
class="col-sm-2 col-form-label">
Topic
</label>
<div class="col-sm-10">
<select id="chooseTopic" class="form-control">
<option selected>Leadership</option>
<option>HR</option>
<option>Sales</option>
<option>Marketing</option>
</select>
</div>
</div>
<fieldset class="form-group">
<div class="row">
<legend class="col-form-label col-sm-2 pt-0"> Type</legend>
<div class="col-sm-10">
<div class="form-check-inline ">
<label class="form-check-label"
for="video"
:class="{'checked':(isChecked==='video')}"
#click="isChecked='video'">
<input class="form-check-input"
type="radio" name="video"
id="video"
v-model="postingType"
value="video" checked>
<i class="fab fa-youtube "></i>
Video
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label"
for="ebook"
:class="{'checked':(isChecked==='ebook')}"
#click="isChecked='ebook'">
<input class="form-check-input"
type="radio"
name="ebook"
id="ebook"
v-model="postingType"
value="ebook">
<i class="far fa-file-pdf "></i>
Ebook
</label>
</div>
<div class="form-check-inline ">
<label class="form-check-label "
for="article"
:class="{'checked':(isChecked==='article')}"
#click="isChecked='article'">
<input class="form-check-input " type="radio"
name="article" id="article"
v-model="postingType" value="article" >
<i class="fas fa-pen-square "></i>
Article
</label>
</div>
</div>
</div>
</fieldset>
</form>
</template>
<script>
export default {
name: "AddPost",
data(){
return{
postingType:'',
isChecked:'video'
}
},
}
</script>
So when I click on ok (next) in add-post component I want the second modal to pop up.
it's right on the bottom of the documentation under Events
basicly use
#ok="yourOkFn"

VueJS + Two instances of vForm in one component

I'm using laravel + VueJS for front-end. I have a groups component to handle groups creation and groups permissions. I need to use two vForms: One to create groups, and the other to create / assign permissions for the group.
The problem is when I send the permissions form, laravel receives data of the first form, this i suppose is because I create that instance first. I think I should create two instances of vForm, but I do not know how. Is this possible?
My component code:
<template>
<div class="container">
<div class="row mt-5">
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Grupos</h3>
<div class="card-tools">
<button class="btn btn-success" #click="newGroupModal" v-if="$can('groupscreate')"> <i class="fas fa-user-plus fa-fw"></i> Nuevo Grupo </button>
</div>
</div>
<!-- /.card-header -->
<div class="card-body table-responsive p-0">
<table class="table table-hover">
<tbody>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Fecha Alta</th>
<th>Fecha Act</th>
<th>Acc.</th>
</tr>
<tr v-for="group in groups" :key="groups.id">
<td>{{ group.id }}</td>
<td>{{ group.name }}</td>
<td>{{ group.created_at | formattedDate }}</td>
<td>{{ group.updated_at | formattedDate }}</td>
<td><i class="fas fa-edit"></i></td>
<td><i class="fas fa-key"></i></td>
</tr>
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="groupModal" tabindex="-1" role="dialog" aria-labelledby="groupModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="groupModal">Nuevo Grupo</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form #submit.prevent="editMode ? updateGroup() : createGroup()">
<div class="modal-body">
<div class="form-group">
<input v-model="form.name" type="text" name="name" placeholder="Name"
class="form-control" :class="{ 'is-invalid': form.errors.has('name') }">
<has-error :form="form" field="name"></has-error>
</div>
</div>
<div class="modal-footer">
<button v-show="editMode" type="button" class="btn btn-danger" #click="deleteGroup" v-if="$can('groupsdelete')">Eliminar</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
<button type="submit" class="btn btn-primary" v-if="$can('groupsedit')">Guardar</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal Permissions-->
<div class="modal fade" id="groupPermissionsModal" tabindex="-1" role="dialog" aria-labelledby="groupPermissionsModal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="userModal">Permisos por Grupo</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form #submit.prevent="updateGroupPermissions()">
<div class="modal-body">
<div class="form-group">
<label class="control-label">Usuarios</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="usersview" value="usersview" v-model="groupPermissions">
<label class="form-check-label" for="usersview">Ver</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="userscreate" value="userscreate" v-model="groupPermissions">
<label class="form-check-label" for="userscreate">Crear</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="usersedit" value="usersedit" v-model="groupPermissions">
<label class="form-check-label" for="usersedit">Editar</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="usersdelete" value="usersdelete" v-model="groupPermissions">
<label class="form-check-label" for="usersdelete">Eliminar</label>
</div>
</div>
<div class="form-group">
<label class="control-label">Grupos</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="groupsview" value="groupsview" v-model="groupPermissions">
<label class="form-check-label" for="groupsview">Ver</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="groupscreate" value="groupscreate" v-model="groupPermissions">
<label class="form-check-label" for="groupscreate">Crear</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="groupsedit" value="groupsedit" v-model="groupPermissions">
<label class="form-check-label" for="groupsedit">Editar</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="groupsdelete" value="groupsdelete" v-model="groupPermissions">
<label class="form-check-label" for="groupsdelete">Eliminar</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
<button type="submit" class="btn btn-primary" v-if="$can('permissionsedit')">Guardar</button>
</div>
</form>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
editMode: false,
groups: {},
groupPermissions: {},
form: new Form({
id: '',
name : '',
}),
formPermissions: new Form({
users: [],
groups: []
}),
}
},
methods: {
newGroupModal(){
this.editMode = false;
this.form.reset();
$('#groupModal').modal('show');
},
newGroupPermissionsModal(groupId){
this.loadGroupPermissions(groupId);
this.form.reset();
$('#groupPermissionsModal').modal('show');
this.form.fill(this.groupPermissions);
},
newEditGroupModal(group){
this.editMode = true;
this.form.reset();
$('#groupModal').modal('show');
this.form.fill(group);
},
loadGroups(){
this.$Progress.start();
axios.get('api/group').then(({data}) => (this.groups = data.data));
this.$Progress.finish();
},
loadGroupPermissions(groupId){
this.$Progress.start();
axios.get('api/permissions/group/' + groupId).then(({data}) => (this.groupPermissions = data));
this.$Progress.finish();
},
createGroup(){
this.$Progress.start();
this.form.post('api/group')
.then(() => {
Fire.$emit('GroupInform');
$('#groupModal').modal('hide');
Toast.fire({
type: 'success',
title: 'Usuario creado satisfactoriamente.'
})
this.form.reset();
this.$Progress.finish();
})
.catch(() => {
this.$Progress.fail();
})
},
updateGroup(groupId){
this.$Progress.start();
this.form.put('api/group/' + this.form.id)
.then(() => {
Fire.$emit('GroupInform');
$('#groupModal').modal('hide');
Toast.fire({
type: 'success',
title: 'Usuario actualizado satisfactoriamente.'
})
this.form.reset();
this.$Progress.finish();
})
.catch(() => {
this.$Progress.fail();
})
},
deleteGroup(){
Swal.fire({
title: 'Estas seguro?',
text: "No podrás restaurar los datos eliminados.",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#d33',
cancelButtonColor: '#14b750',
confirmButtonText: 'Si'
}).then((result) => {
if (result.value) {
this.form.delete('api/group/'+this.form.id).then(()=>{
Toast.fire({
type: 'success',
title: 'Usuario eliminado satisfactoriamente.'
})
Fire.$emit('GroupInform');
$('#groupModal').modal('hide');
}).catch(()=> {
Swal.fire("Error!", "Algo anda mal.", "warning");
this.$Progress.fail();
});
}
})
},
updateGroupPermissions(){
this.$Progress.start();
this.form.post('api/permissions/group/1')
.then(() => {
Fire.$emit('GroupInform');
$('#groupModal').modal('hide');
Toast.fire({
type: 'success',
title: 'Usuario actualizado satisfactoriamente.'
})
this.form.reset();
this.$Progress.finish();
})
.catch(() => {
this.$Progress.fail();
})
}
},
mounted() {
this.loadGroups();
Fire.$on('GroupInform', () => {
this.loadGroups();
});
}
}
</script>
Simply add a new variable with a different name than 'form' as a new instance from v-form
form2: new Form({
id: '',
name : '',
})
then access it like that:
<div class="form-group">
<input v-model="form2.name" type="text" name="name" placeholder="Name" class="form-control" :class="{ 'is-invalid': form.errors.has('name') }">
<has-error :form="form2" field="name"></has-error>
</div>