I got this to work and I wanted to share it in case it is helpful, or in
case you have comments. First some explanation:
- loading jquery in the .html puts the jquery library in the top
context, that is why it was not working out of the box for me
- pyjs is creating the components in the top document too
- so now we have jquery in the top context, and the created component in
the top context. Since jQuery uses by the default the context in which it
was loaded to look for components, we just need to use the top jQuery. To
do that, we need the top. prefix.
The resulting code looks like this:
import pyjd # this is dummy in pyjs
from pyjamas.ui.HTML import HTML
from pyjamas.ui.RootPanel import RootPanel
from __pyjamas__ import JS
class jQueryTest:
def onModuleLoad(self):
html = HTML('<p><input type="hidden" id="aa10" style="width:300px"
value="brown, red, green"/></p>')
RootPanel().add(html)
JS("""top.jQuery("#aa10").select2({tags:["red", "green",
"blue"]});""")
if __name__ == '__main__':
pyjd.setup("./public/jQueryTest.html")
app = jQueryTest()
app.onModuleLoad()
pyjd.run()
And the related .html:
<html>
<head>
<script src="jquery-1.7.2.min.js"></script>
<link rel="stylesheet" href="select2.css" />
<script src="select2.js"></script>
<meta name="pygwt:module" content="jQueryTest">
<title>Test jQuery!</title>
</head>
<body bgcolor="white">
<script language="javascript" src="bootstrap.js"></script>
<iframe id='__pygwt_historyFrame' style='width:0;height:0;border:0'
></iframe>
</body>
</html>
This is working with pyjs as standalone application. Now I have pyjs
embedded in a web2py container. Let's see if I get this to work.
Regards,
Daniel