leave review in that Modal I" /> leave review in that Modal I" /> leave review in that Modal I"/>

How to get data from calling page while in Ion Modal

203 views Asked by At

On one of my pages (which has

<button class="button button-small button-balanced" data-ion-modal="reviewPopup">
    leave review
</button>

in that Modal I have a form that, when I click a button for, should send data to the server from both the Modal and the template from template a. I can get data from the form in the Modal just fine, but I can't access any data from the calling page (specifically I need the _id). Calling Template.parentData just returns null.

2

There are 2 answers

0
JeremyK On

I believe that Template.parentData (from the modal) will be returning either the body template, or another top level template specific to the meteoric framework. Either way, If you were using a different framework where you specifically add the modal template to the page somewhere I'd suggest passing in _id as a template parameter.

But with meteoric, as far as I know, you can't do that - so you may have to use something with global scope.

If you are using a router, and have the _id as part of the route, get it from there (e.g. FlowRouter.current().params ).

Or just use the simplest option and use a Session variable. Set it in a onRendered function, access it in the Modal's event functions

0
insaneinc On

Instead of triggering the modal from the template using data-ion-modal="reviewPopup", you can trigger the Modal from your button event, for example -

Template.templateName.events({
  'click #review-popup': function() {
     //capture data from parent template first
     //....
     var parentDataContext = {some data}

     IonModal.open("reviewPopup", parentDataContext);
  }
})

After the modal opens, the parent data can be accessed using this in the modal helpers.