If I bind with MySelect2TaggingComponent().change (as explained in the
stack overflow answer) I would be creating a
new MySelect2TaggingComponent object, which I do not want. I want to bind
to the change method of the object which has defined the whole Select2
elements. That is why I am trying with self["change"] and this.change
(which I guess refer to the same thing)
On the other hand, I do not know how to match the concept of anonymous
function in javascript to my MySelect2TaggingComponent.change method.
"function { ... }" is an anonymous function, which I can not relate to the
change method.
Finally, I have tried binding to window.change, like this:
myjs = 'parent.jQuery("#%s").bind("change", window.change);' % (self.myid)
There are no errors, but the change method is not triggered :(
Regarding pyjd: I have tried, but since I am using JS statements, it is
failing early.
I thank you very much for your support and I understand that you are
probably very busy!
Nevertheless, if you ever get the time to take a look at my example, it
would be very helpful. I copy paste here the commands that you need:
mkdir xxx ; cd xxx
git clone [email protected]:gonvaled/pyjs.git
cd pyjs/examples
python jquery-select2 --download
Thanks and regads,
Daniel
On Wednesday, July 11, 2012 12:06:38 AM UTC+2, peter.bittner wrote:
>
> Here are some links that could help find the solution:
>
>
> http://stackoverflow.com/questions/9245657/typeerror-unbound-method-method-name-must-be-called-with-class-name-instanc
>
> http://api.jquery.com/bind/
>
> The first one is ... aahh! ... a Python answer!! In the jQuery
> documentation I read things like "$(this).foo" and binding always with
> "function { ... }", which I would try literally. Also if "change =
> wnd().change" the function could by - *guessing wildly* - be available
> as "window.change"?
>
> Sorry that I don't try to get your example working hands-on. I'm on
> some other project in parallel that I need to get going... :-(
>
> Peter
>
>
> 2012/7/10 Peter Bittner <[email protected]>:
> > Daniel,
> >
> > 2012/7/10 Daniel Gonzalez <[email protected]>:
> > ...
> >> myjs = 'parent.jQuery("#%s").bind("change", this.change);' %
> (self.myid)
> >> Uncaught TypeError: unbound method change() must be called with
> >> MySelect2TaggingComponent instance as first argument (got '[object
> Object]'
> >> instead)
> >>
> >> myjs = 'parent.jQuery("#%s").bind("change", self["change"]);' %
> (self.myid)
> >> Uncaught TypeError: unbound method change() must be called with
> >> MySelect2TaggingComponent instance as first argument (got '[object
> Object]'
> >> instead)
> >>
> >> myjs = 'parent.jQuery("#%s").bind("change", change);' % (self.myid)
> >> jQuerySelect2 AttributeError: change is not defined
> >
> > Just a quick thought: have you tried running your example with pyjd
> > instead of pyjs? If that works there may be a Python stack trace that
> > helps much more than the "Uncaught TypeError:" error message that come
> > from ... whom? Can you try?
> >
> > Peter
> >
> >
> >> You can see the code (not yet working) in my fork:
> >>
> https://github.com/gonvaled/pyjs/blob/master/examples/jquery-select2/jQuerySelect2.py#L45
>
> >>
> >> You can compile the jquery-select2 example like this: python
> jquery-select2
> >> --download (in the examples directory). Output goes to
> examples/__output__
> >>
> >> Br,
> >> Daniel
> >>
> >> On Saturday, July 7, 2012 9:56:36 PM UTC+2, istvan.vago wrote:
> >>>
> >>> Daniel,
> >>> try this:
> >>>
> >>> from __pyjamas__ import wnd
> >>>
> >>> class MySelect2TaggingComponent(HTML):
> >>>
> >>> def change(self):
> >>> ...
> >>>
> >>> wnd().change=change
> >>>
> >>> The change method will be accessible from jQuery as "change".
> >>>
> >>> Istvan
>