How to hide a bootstrap-vue modal after clicking a button in laravel vuejs2019 Community Moderator ElectionMultiple forms on a pageHow to use a bootstrap dialog as a vueJs component?onclick action slower than css :focus selector switchManaging which bootstrap-vue modal is open through vuex stateHow to load bootstrap-vue into Laravel 5 with laravel-mix?bootstrap-vue modal not displayingBootstrap-vue: how to pass data to modal?Vue JS v-if not updating data on loginbootstrap 4 modal not showing after button is clicked with VueJsBootstrap-vue open modal from modal
If sound is a longitudinal wave, why can we hear it if our ears aren't aligned with the propagation direction?
Cycles on the torus
Is there a math expression equivalent to the conditional ternary operator?
Is there a logarithm base for which the logarithm becomes an identity function?
Why do phishing e-mails use faked e-mail addresses instead of the real one?
Do Paladin Auras of Differing Oaths Stack?
The (Easy) Road to Code
Are all players supposed to be able to see each others' character sheets?
cannot log in to the server after changing SSH port
Create chunks from an array
One circle's diameter is different from others within a series of circles
Use Mercury as quenching liquid for swords?
Under what conditions can the right to remain silent be revoked in the USA?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
How to copy the rest of lines of a file to another file
Is divide-by-zero a security vulnerability?
Numerical value of Determinant far from what it is supposed to be
What can I do if someone tampers with my SSH public key?
What sort of fish is this
Trocar background-image com delay via jQuery
Traveling to heavily polluted city, what practical measures can I take to minimize impact?
Movie: boy escapes the real world and goes to a fantasy world with big furry trolls
School performs periodic password audits. Is my password compromised?
Can I negotiate a patent idea for a raise, under French law?
How to hide a bootstrap-vue modal after clicking a button in laravel vuejs
2019 Community Moderator ElectionMultiple forms on a pageHow to use a bootstrap dialog as a vueJs component?onclick action slower than css :focus selector switchManaging which bootstrap-vue modal is open through vuex stateHow to load bootstrap-vue into Laravel 5 with laravel-mix?bootstrap-vue modal not displayingBootstrap-vue: how to pass data to modal?Vue JS v-if not updating data on loginbootstrap 4 modal not showing after button is clicked with VueJsBootstrap-vue open modal from modal
I am new to laravel and vue.js.
In a blade view, I have a bootstrap-vue modal which includes a vue.js component for a full-text search and sends a post request to the backend when clicking a button.
So I want to hide this modal after clicking the same button after performing the request.
I have tried to access modal using ref attribute and then call the hide() method as stated in the documentation here, but it doesn't work, I don't know what I am missing.
Here is my code:
index.blade.php:
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!-- The modal -->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<user-search />
</b-modal>
</div>
</div>
</div>
@endsection
UserSearch.vue:
<template>
<div class="" ref="myModalRef">
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div v-if="usersToAdd.length" class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</div>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd);
</script>
<style scoped>
</style>
laravel vue.js bootstrap-vue
add a comment |
I am new to laravel and vue.js.
In a blade view, I have a bootstrap-vue modal which includes a vue.js component for a full-text search and sends a post request to the backend when clicking a button.
So I want to hide this modal after clicking the same button after performing the request.
I have tried to access modal using ref attribute and then call the hide() method as stated in the documentation here, but it doesn't work, I don't know what I am missing.
Here is my code:
index.blade.php:
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!-- The modal -->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<user-search />
</b-modal>
</div>
</div>
</div>
@endsection
UserSearch.vue:
<template>
<div class="" ref="myModalRef">
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div v-if="usersToAdd.length" class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</div>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd);
</script>
<style scoped>
</style>
laravel vue.js bootstrap-vue
add a comment |
I am new to laravel and vue.js.
In a blade view, I have a bootstrap-vue modal which includes a vue.js component for a full-text search and sends a post request to the backend when clicking a button.
So I want to hide this modal after clicking the same button after performing the request.
I have tried to access modal using ref attribute and then call the hide() method as stated in the documentation here, but it doesn't work, I don't know what I am missing.
Here is my code:
index.blade.php:
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!-- The modal -->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<user-search />
</b-modal>
</div>
</div>
</div>
@endsection
UserSearch.vue:
<template>
<div class="" ref="myModalRef">
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div v-if="usersToAdd.length" class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</div>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd);
</script>
<style scoped>
</style>
laravel vue.js bootstrap-vue
I am new to laravel and vue.js.
In a blade view, I have a bootstrap-vue modal which includes a vue.js component for a full-text search and sends a post request to the backend when clicking a button.
So I want to hide this modal after clicking the same button after performing the request.
I have tried to access modal using ref attribute and then call the hide() method as stated in the documentation here, but it doesn't work, I don't know what I am missing.
Here is my code:
index.blade.php:
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!-- The modal -->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<user-search />
</b-modal>
</div>
</div>
</div>
@endsection
UserSearch.vue:
<template>
<div class="" ref="myModalRef">
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div v-if="usersToAdd.length" class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</div>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd);
</script>
<style scoped>
</style>
laravel vue.js bootstrap-vue
laravel vue.js bootstrap-vue
asked Mar 6 at 13:58
NasKehilNasKehil
269
269
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The problem with your code is bootstrap-vue was not able to find the modal reference correctly.Try something like this,
Remove modal from your index.blade.php and include it in UserSearch.vue with the ref attribute
index.blade.php
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!--Removed modal tag from here and included it in UserSearch.vue-->
<user-search />
</div>
</div>
</div>
@endsection
UserSearch.vue
<template>
<!--Add b-modal tag and ref attribute here-->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true" ref="myModalRef">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</b-modal>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd).then(response =>
//Do something you want
this.$refs.myModalRef.hide();
).catch(error =>
//Handle the errors
this.$refs.myModalRef.hide();
)
</script>
<style scoped>
</style>
Inside your "sendInviteToUsers" function edit the function as above. In here the modal will close after you receive the api response from the server.
New contributor
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024863%2fhow-to-hide-a-bootstrap-vue-modal-after-clicking-a-button-in-laravel-vuejs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem with your code is bootstrap-vue was not able to find the modal reference correctly.Try something like this,
Remove modal from your index.blade.php and include it in UserSearch.vue with the ref attribute
index.blade.php
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!--Removed modal tag from here and included it in UserSearch.vue-->
<user-search />
</div>
</div>
</div>
@endsection
UserSearch.vue
<template>
<!--Add b-modal tag and ref attribute here-->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true" ref="myModalRef">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</b-modal>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd).then(response =>
//Do something you want
this.$refs.myModalRef.hide();
).catch(error =>
//Handle the errors
this.$refs.myModalRef.hide();
)
</script>
<style scoped>
</style>
Inside your "sendInviteToUsers" function edit the function as above. In here the modal will close after you receive the api response from the server.
New contributor
add a comment |
The problem with your code is bootstrap-vue was not able to find the modal reference correctly.Try something like this,
Remove modal from your index.blade.php and include it in UserSearch.vue with the ref attribute
index.blade.php
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!--Removed modal tag from here and included it in UserSearch.vue-->
<user-search />
</div>
</div>
</div>
@endsection
UserSearch.vue
<template>
<!--Add b-modal tag and ref attribute here-->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true" ref="myModalRef">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</b-modal>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd).then(response =>
//Do something you want
this.$refs.myModalRef.hide();
).catch(error =>
//Handle the errors
this.$refs.myModalRef.hide();
)
</script>
<style scoped>
</style>
Inside your "sendInviteToUsers" function edit the function as above. In here the modal will close after you receive the api response from the server.
New contributor
add a comment |
The problem with your code is bootstrap-vue was not able to find the modal reference correctly.Try something like this,
Remove modal from your index.blade.php and include it in UserSearch.vue with the ref attribute
index.blade.php
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!--Removed modal tag from here and included it in UserSearch.vue-->
<user-search />
</div>
</div>
</div>
@endsection
UserSearch.vue
<template>
<!--Add b-modal tag and ref attribute here-->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true" ref="myModalRef">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</b-modal>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd).then(response =>
//Do something you want
this.$refs.myModalRef.hide();
).catch(error =>
//Handle the errors
this.$refs.myModalRef.hide();
)
</script>
<style scoped>
</style>
Inside your "sendInviteToUsers" function edit the function as above. In here the modal will close after you receive the api response from the server.
New contributor
The problem with your code is bootstrap-vue was not able to find the modal reference correctly.Try something like this,
Remove modal from your index.blade.php and include it in UserSearch.vue with the ref attribute
index.blade.php
@extends('layouts.app', ['navId' => 'teams'])
@section('title', 'Teams')
@section('content')
<div class="container-fluid mt-5 pt-5 col-10">
<div class="row">
<div class="col-3 offset-6">
<b-button v-b-modal="'myModal'">Add Users</b-button>
<!--Removed modal tag from here and included it in UserSearch.vue-->
<user-search />
</div>
</div>
</div>
@endsection
UserSearch.vue
<template>
<!--Add b-modal tag and ref attribute here-->
<b-modal id="myModal" class="" size="s" centered :hide-footer="true" :hide-header="true" ref="myModalRef">
<div class="row justify-content-center">
<h4 class="">Add new Participant</h4>
</div>
<div class="card">
<input type="text" placeholder="Search ..." v-model="keywords" v-on:keyup="autoComplete"
class="form-control bg-light border-0">
<div class="panel-footer mt-2" v-if="results.length">
<ul class="list-unstyled">
<div class="result-item my-3">
<li class="media mx-2 my-3" v-for="result in results" :key="result.id" @mouseover="hover = true"
@mouseleave="hover = false"
:class=" active: hover ">
<img :src="result.avatar_path ? result.avatar_path : '/img/dashboard/user-placeholder.png'"
class="rounded-circle align-self-center mr-3" width="40" height="40"/>
<h5 v-text="result.name" class="mt-3"></h5>
<div class="media-body d-flex justify-content-end mt-3">
<b-form-checkbox :id="'selected-user' + result.id" v-model="usersToAdd" :value="result" class="" />
</div>
</li>
</div>
</ul>
</div>
</div>
<div class="col-3 my-5 mx-auto">
<b-button type="submit" @click="sendInviteToUsers">Done</b-button>
</div>
</b-modal>
</template>
<script>
import bForm from 'bootstrap-vue/es/components/form/form';
import bFormGroup from 'bootstrap-vue/es/components/form-group/form-group';
import bFormInput from 'bootstrap-vue/es/components/form-input/form-input';
export default
name: 'UserSearch',
data()
return
keywords: '',
results: [],
hover: false,
usersToAdd: [],
;
,
methods:
autoComplete()
this.results = [];
if(this.keywords.length > 2 )
this.$axios.get('/api/users/search', params: keywords: this.keywords )
.then(response =>
this.results = response.data;
)
.catch(() =>
this.loading = false;
this.showErrorToast('An error occurred while Fetching Users. Please try again later');
);
// .catch(error => );
,
sendInviteToUsers()
if(this.usersToAdd.length)
this.$axios.post('/api/teams/invite-with-email/', this.usersToAdd).then(response =>
//Do something you want
this.$refs.myModalRef.hide();
).catch(error =>
//Handle the errors
this.$refs.myModalRef.hide();
)
</script>
<style scoped>
</style>
Inside your "sendInviteToUsers" function edit the function as above. In here the modal will close after you receive the api response from the server.
New contributor
New contributor
answered Mar 7 at 7:40
user3581438user3581438
361
361
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024863%2fhow-to-hide-a-bootstrap-vue-modal-after-clicking-a-button-in-laravel-vuejs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown