Adding JS to embed portlet

I'm trying to put some simple javascript (create a pulldown that goes to defined webpage when selected). I'll post the question here, then give details.

For a simple html page, I'm fine getting it to work; however, in Plone, it dispalys but the actions don't work. Based on my research, it looks like for Plone it is not as simple as pasting JS into the raw HTML.

  1. i am using Plone 5 with Embed Portlet because it allows me to add html.

when I add this JS:

-------Choose a Selection------- Disbursements Start Booster ======================

It works in that the pulldown box is visible (test site: wayne.lwhsboosters.org)

however, the action doesn't work (doesn't go to website when selected.)

I found various helpful sites:


https://training.plone.org/5/javascript/exercises/1.html

So, am I correct in that one or both of these sites shows how JS is added and simply pasting as part of raw HTML won't get it done.

Thanks for pointer. If it is (for me) as complicated as above, that will tell me I can either use simple HTML hyperlink from the portlet or hire a programmer if I want JS.

Note: I just noted that above the Block where code is added in the embed Portlet, is the following text:
"HTML Code to embed The html snippet you want to use. It can be iframe, javascript, html"
So, should JS work here?

Thanks for any help

You dont say what console output you get after pasting js in the embed portlet. I think it should work as it is meant to bypass plone security if its the one I think. If I'm wrong then it is safehtml stripping out js and this js for security reasons.
Either way its really not a nice way of doing it.
Better to follow the tutorial to get a js file included in your page and then use some jquery onload to attach the behaviour to your select by Id. You can also add include a js file in your theme just via the theme editor the manifest. None of that zcml needed

alternatively you can try the portlet included in collective.blueline, a package we created for inserting this kind of stuff all over a Plone site.

@hvelarde thanks for the suggestion. I tried this in Plone 5. I instlled as described, and the installed/activated the product. all went fine.

Then I tired to add it to a portlet and got the "Modal" error. Here is the error details.

Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module plone.app.portlets.browser.formhelper, line 59, in call
Module z3c.form.form, line 233, in call
Module plone.z3cform.fieldsets.extensible, line 58, in update
Module plone.autoform.form, line 33, in updateFields
Module plone.autoform.base, line 54, in updateFieldsFromSchemata
Module plone.autoform.form, line 22, in schema
NotImplementedError: The class deriving from AutoExtensibleForm must have a 'schema' property

thanks, Wayne; I've seen this before in collective.polls. Do you mind opening a new issue in the package issue tracker?

ca someone confirm that portlets in Plone 5 are based on z3c.form also?

Check this:

1 Like

awesome! I tested it and is working; I'm merging the branch now:

@rileydog can you give a try to this on the master branch afterwards? if it works to you I can make a new release.

note that, by default, the portlet is shown to anonymous users only; you can change that on the control panel configlet.

@hvelarde thanks for the help. I will try this and post back.

@alert thanks, I see this might help.