Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSSource injected multiple times #57

Open
Cito opened this issue Oct 2, 2012 · 0 comments
Open

JSSource injected multiple times #57

Cito opened this issue Oct 2, 2012 · 0 comments

Comments

@Cito
Copy link
Contributor

Cito commented Oct 2, 2012

Another problem I noticed when trying to adapt a TW1 app to TW2:

When a widgets uses a JSLink as a resource, then this JSLink will only be injected once on the same page, however, when it uses a JSSource as a resource, then this JSSource will be injected as many times as the widgets appears on the page.

Here is a typical use case that demonstrates the problem:

import tw2.core as twc, tw2.forms as twf
import tw2.devtools as twd

class MyField(twf.TextField):
    resources = [twc.JSLink(link='some_plugin'),
        twc.JSSource(src="$('.myfield').init_plugin()")]
    css_class = 'myfield'

class Index(twf.FormPage):
    title = "Test"
    class child(twf.TableForm):
        field1 = MyField()
        field2 = MyField()

twd.dev_server()

When you run this code, you will see that the plugin link is only injected once in the head of the page, but the initialization code is inserted twice at the bottom of the page, which is usually not what you want, and different from the behavior of TW1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant