Simple edit layout - javascript not firing after saving contents in edit plus

(Erwin Strobel) #1


I am using a Simple edit layout, applied as part of content container template.

Within this layout, I have some js that is used to hide or display fields depending on the value of a select field.

Everything works fine in edit plus on page load (e.g. when the select field value is changed, fields hide or show accordingly), however once the the page (contents screen) has been saved, it’s almost as if the js code is disabled.

After saving the page, the correct fields are visible (as in the fields are displaying in accordance to the select value prior to pressing the save button), however now when the select value is changed, fields no longer show or hide instantly (changes only take a effect once the page is saved again).

I’m quite certain the issue is not with the js code itself, as I’ve tried bare bones js with just an alert, and the page behaves the same way … and everything works perfectly in the admin interface

Just wondering if anyone knows what would be causing this issue?

(Erwin Strobel) #2

If anyone else has this issue, I found a work around:

Load a div dynamically with js. I gave the div an id of “%asset_assetid%selectDiv”.

I also placed my script in a div with the id of “script%asset_assetid%” (I used %asset_assetid%, as the script div gets loaded every time the simple edit layout is applied to a container div on the page, so needs it to be unique).

With this, I also set up some js that runs when the “selectDiv” div is removed from the dom (this happens when the page is saved in edit plus). This script basically just replaces the script div with it’s own contents a second after the selectDiv was removed from the dom.

The JS from the simple edit layout now works after the page has been saved in edit plus!


$("#%asset_assetid%selectDiv").on(“remove”, function () {
var newState = -1;
setTimeout(function () {
if (newState == -1) {
}, 1000);