Modal Return Values #44
-
Currently, there doesn't seem to be any support for returning values on modal close. It would be very useful if you could pass an argument to |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Interesting idea. Sometimes ago i do something like this: const modal = openModal(SomeVueComponent, {
close: async (values) => {
const data = await API.request(values);
...and then update my parent component
}
}) And in the modal {
props: {
close: Function
},
data: () => ({userName: null}),
async beforeModalClose(){
await this.close(userName);
return true;
}
} But I doubt this solution will work for everyone. Also, You are right when you say that there is no access to the modal data in the onclose method. I will try to resolve this Issue. Maybe by adding field target that was a link to modal instance. const modal = await openModal({data: () => ({
userName: null
})})
modal.onclose = () => modal.target.userName But maybe i will find more better solution I will spend to it some time and then write in this discussion my result. |
Beta Was this translation helpful? Give feedback.
-
Also, we can use something like it: //Modal.vue
{
props: {
val: String
},
data: () => ({
insideValue: 123
})
} const m = await openModal(Modal, {val: "qwerty"});
m.onclose = function(){ //working only with function, not onclose = () => {...
console.log("This:", this); // this is instance of VueModalComponent
console.log(this.val); // "qwerty"
console.log(this.insideValue); // 123
} I will put information about it in docs |
Beta Was this translation helpful? Give feedback.
-
I update only github version const modal = await openModal(Modal)
modal.el
modal.elem
modal.target
modal.inst
modal.instance // Current
modal.getInstance() |
Beta Was this translation helpful? Give feedback.
-
I update version of package. 1.4.7 const modal = await openModal(Modal);
modal.instance Also update information about onclose function and access to modal instance: //Modal.vue
{
props: {},
data: () => {
return {
insideValue: "Hello"
}
}
} const modal = await openModal(Modal);
modal.onclose = function(){
this.insideValue; // "Hello"
modal.instance.insideValue; // "Hello"
} How to pass values to onclose function i dont resolve, because you can execute closeModal in any point in your application, so in one place, for example in he modal, u can pass some values to closeModal, but in other component u dont have access to modal's values and in result you will execute closeModal without paramters. Result:
const fn = () => doSome;
const modal = await openModal(Modal, {callback: fn})
***
And execute this function in beforeModalClose or onBeforeModalClose |
Beta Was this translation helpful? Give feedback.
I update version of package. 1.4.7
For more information: docs
I add instance prop to ModalObject:
Also update information about onclose function and access to modal instance:
How to pass values to onclose function i dont resolve, because you can execute closeModal in any point in your application, so in one place, for example in he modal, u can pass some values to closeModal, but i…