2amigos / yiiwheels

Widget extension library for the YiiStrap extension
http://yiiwheels.2amigos.us
Other
133 stars 77 forks source link

Switch not working after 2nd Pjax #115

Closed BrainFeeder closed 10 years ago

BrainFeeder commented 10 years ago

Not sure if this is an issue with the plugin but I'm struggling with this for a while now. In my application pages get loaded by pjax requests. On one page I use the Bootstrap Switch. When I visit it the first time, all seems to be OK, but when I browse some other pages and return to the page with the switch it just displays as a checkbox.

I allready prevented jQuery from loading twice on an ajax request etc, components I made using jQuery do work each time I visit a page which uses them. The Switch plugin seems the only thing failing in this case.

Any ideas? thanks!

tonydspaniard commented 10 years ago

It is not the plugin and its the plugin, let me explain. The plugin doesn't initialize for live events. What you need to do is to hook the pjax event 'pjax:complete' with a reinitialization of the switch button if found.

Yii2 works with pjax at its core, check my solution for the challenge I had with the editable column: https://github.com/2amigos/yii2-grid-view-library/blob/master/assets/editable/js/dosamigos-editable.column.js#L153

BrainFeeder commented 10 years ago

Thanks for the help. I managed to get it working. There is this other error which I can't figure out. The Masked input plugin does not load at all. In the console I get the error: "TypeError: $(...).mask is not a function".

/* In the .js file I noticed "$.mask" is used instead of "$.fn.mask". Since their are so many models (which I haven't tried all) so I am not sure if this was a typo. It seems to be consequently used in the file as "$.mask". */

Never mind the previous part. Since I have tried many things trying to get it to work (even updating the plugin to the latest version) I forgot that it was not the original file that is included in this state of the art Yii extensions :) Anywayz, I get the same error if I put the original 0.9.0 version back in place.

tonydspaniard commented 9 years ago

@BrainFeeder So this issue is not solved?