Can't access jquery in template rendered?


#1

Can’t access jquery in template rendered

Template.productDetail.onRendered(function () {
   $('.selector').inputmask(.............);
});

And then I tried open the browser console and do agian, It is work fine.
Please help me.


Function to convert of string like this: "12 -> 12, 21" - "123 -> 123, 132, 231, 213, 312, 321"?
#2

template HTML code would be useful…


#3

excuse me, could you explain?


#4

It is hard to comment when we see just 1 line in onRendered pointing to some selector class
but not HTML part of template where that class should be used.
Is it directly in that template, or in some child template ? etc…
paste more code, best would be whole HTML of productDetail template


#5

I have any problem for init jquery package such as inputmask, dateTimePicker... within template rendered

// html
<template ...>
        {{#autoForm collection=Exchange id="cpanel_exchangeUpdate" data=this type="update"}}
           {{> afQuickField name="exDate" type="text"}}
           {{> afQuickField name="exAmount" type="text"}}
        {{/autoForm}}
</template>

And the I would like to init the text box with

// Js
Template.myTpl.onRendered(function () {
   $('[name="exDate"]').datetimepicker(.............);
   $('[name="exAmount"]').inputmask(.............);
});

Don’t work, and then I tried open the browser console and do again it work fine.


#6

Cause autoform is separate template on it’s own and quickFields have their own templates.

I would suggest to create your own templates for these afQuickField’s and init them inside these templates.
I used custom template in my blog, but without customizing it’s own onRendered.
Maybe it will inspire you how to do it yourself.


#7

And I would look for autoform plugins, for example https://atmospherejs.com/aldeed/autoform-bs-datetimepicker


#8

Thanks for your helping, some init plugins don’t work (mostly on update form).
I don’t understand how to init it after view is ready.


#9

well, onRendered means that static html of given template is ready.
but all other child templates or #each #with #if blocks etc does not have to be yet


#10

Could you example me through your advice: .......I would suggest to create your own templates for these afQuickField's and init them inside these templates.................


#11

in pasted blog I used custom template, if you add your own JS file for it where you initialize it as datepicker, it would become datepicker.

but, there is already autoform plugin for that.


#12

In this case I would like to use inputmask with autoform


#13

I have nothing else to add.
Good luck.