Data context not set for modal


#1

Hi guys, I have succesfully loaded data into a modal in my application and on trying to do it again with another object I am having no success.

The blaze template doesn’t get any data although it is set. Why could this be and how can I better debug it?

My template logic is doing the following:

Template.orderCart.events
	'click #confirmOrder': (event) ->
		orders = Orders.find({}).fetch()
		Session.set 'orders', orders
		Modal.show 'confirmOrderEmailModal', orders

Template.confirmOrderEmailModal.helpers
	'orders': () ->
		orders = Session.get 'order'
		return orders

And display is as follows:

<template name="confirmOrderEmailModal">
    <div class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-header">
                    <h4 class="modal-title">Confirm Purchase Order</h4>
                </div>

                <div class="modal-body">
                    <p>
                      <ul class="list-group">
                        {{#each orders}}
                    		  {{> orderItem}}
                    		{{/each}}
                      </ul>
                      <button type="button" class="btn btn-success">Confirm Order</button>
										</p>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>

            </div>
        </div>
    </div>
</template>

The {{each orders}} is empty, but in another part of my app where I am using exactly the same method the data is set.

Really cannot figure out why this is. If I console.log orders from the template logic in the coffeescript the data is there. So how can I ensure the modal gets the data context?

Thanks in advance as this bug is all that prevents my app from being finished.

All the best!


#2

You seem to have made a typo:

Template.confirmOrderEmailModal.helpers
	'orders': () ->
		# orders = Session.get 'order'
		orders = Session.get 'orders'
		return orders

#3

wow… thanks so much!!


#4

yeh it works like a dream … seriously need to get more sleep can’t believe it was just that. 2 hours of debugging for this. thanks man really!!


#5

haha, well that happens to everyone all the time. don’t beat yourself up for this :slight_smile:


#6

Now I just have one last issue, the value {{title}} is empty, but quantity is set.

This is only when displaying in the modal, when I use the same each loop to iterate the object in another part of the template it is set and displaying fine.

<template name="orderItem">
    <li class="list-group-item">{{title}} ({{quantity}})
    {{#afModal title="Remove from order" class="text-danger" prompt="Are you sure you wish to remove this from your order?" collection="Orders" operation="remove" doc=_id formId="removeOrder"}}
      <i class="fa fa-times" buttonContent="Delete"></i> {{_ "delete"}}
    {{/afModal}}</li>
</template>

title is set in the collection via a helper, I have checked in the console and it is being set:

Orders.helpers
	title: ->
		product = Products.findOne(@productId)
		return product.title

What is making the title not be set in the modal, but display fine when loop in a template block?

Thanks!


#7

update: I’ve worked around this for now by just duplicating the field in the orders collection as I found that once the data is saved the the Session var I cannot no longer use the helper function and so the only way to get the join data across is to duplicate.

Is this a known issue or is there another way to work with Session variables so that helper functions remain available? Or is joining between connections done in another way?


#8

@tomtom87 collection helpers work on the collection cursor.

but you are storing a “document” on your session variable. it is no longer a cursor.

you could create an “orders” helper instead and use that instead of a session variable.

Template.registerHelper('orders', function() {
  return Orders.find();
})

There are other possible ways to achieve this and this is probably not the best way as it is, but should work better than a session helper.


#9

ah i see I can just make a helper on the template! Thanks man very useful.