Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

javascript in custom Widgets and Ajax mode #6

Open
croaker000 opened this issue Jan 15, 2013 · 4 comments
Open

javascript in custom Widgets and Ajax mode #6

croaker000 opened this issue Jan 15, 2013 · 4 comments
Assignees
Labels

Comments

@croaker000
Copy link

Regarding https://sourceforge.net/projects/p4a/forums/forum/340765/topic/5905682

This could do with being fixed for three reasons:

1 - The custom widget may have it's own P4A ID attribute but if we can't reference that in javascript attached to the application's mask. If there's two widgets, they need different IDs and we can easily handle that if the javascript was in the getAsString() of the custom widget
2 - We can set up variables and constants as part of the widget object but we can't get at those from javascript written as part of the parent mask.
3 - To include the custom widget in your application, you need more configuration to set it up, you can't just drop the widget into your application directory, reference it in a build() function and then expect it to work straight away. You have to copy the widget and then insert the javascript manually. It's sort of OK if you wrote the widget yourself, know how it works and what's needed. It's not OK if you want to release the widget for others to download and use - there's lots of special instructions needed and maybe more support questions...

I'm happy to help debug this issue.

@fballiano
Copy link
Owner

Hello,
I think this is not really an issue, i mean, take a look at the rich_textarea html/javascript template file here:
https://github.com/fballiano/p4a/blob/master/themes/default/widgets/rich_textarea/rich_textarea.php
it should be self-explanatory about how to get the widget id and how to use it in the javascripts.

This should solve points 1 and 2.

For the third point I suggest you to take a look at the p4a_graph main file (it's a contrib):
https://github.com/fballiano/p4a-contribs/blob/master/graph/objects/p4a_graph.php
I know it doesn't have a proper template file but you can easily require it inside the getasstring fuction

For the "installation" or a contrib widget I always suggest you to put everything inside the "libraries" folder of your application, it's the best place to keep everything in order.

Let me know

@ghost ghost assigned fballiano Jan 15, 2013
@croaker000
Copy link
Author

There are work-arounds, sure. it just seems counter-intuitive to have to do that. If you can point me in the right direction, I'm happy to work on this solution myself

@fballiano
Copy link
Owner

they're not workaround, it's the way you gather widget's ids in p4a's javascript.
also cause javascripts could be different from a widget instance to another so..

@croaker000
Copy link
Author

Did you read the original Forum thread, you suggested I raise it as an issue here.
https://sourceforge.net/projects/p4a/forums/forum/340765/topic/5905682

I still maintain a widget's javascript should be coded into the widget itself, not added to as part of the parent mask.

I know it doesn't have a proper template file but you can easily require it inside the getasstring fuction

I'm not convinced even this works. In ajax mode, all additional <script></script> code is dropped. All that's kept is what you put inside an onclick="" attribute.

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

No branches or pull requests

2 participants