Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Onchange event in CMS


Reply

3 Posts   1382 Views

Avatar
UncleCheese

3 September 2008 at 4:13am 4085 Posts

I'm trying to unobtrusively attach an onchange event to a select box on my CMS page. I've figured out that i can add custom script to a specific module using the augmentInit() function off the DataObjectDecorator.

What's confusing to me is that the window.onload() event seems to fire when the silverstripe logo comes up, which is before my select box is loaded into the DOM.

Anyone know how this is usually done?

Avatar
ajshort

3 September 2008 at 9:58am (Last edited: 3 September 2008 9:58am), Community Member, 244 Posts

Hi UncleCheese,

something like this is normally used:

Behaviour.register({
   'select.domSelector' : {
      initialize: function () {
         // etc
      },
      onclick: function() {
         //etc
      }
   }
});

Not only will this get applied on page startup, but itll also be reapplied whenever a page is loaded using AJAX.

Avatar
UncleCheese

4 September 2008 at 5:08am 4085 Posts

Perfect! What a great solution. So glad I posted here. I was sure no one would have an answer!