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   1409 Views

Avatar
UncleCheese

Forum Moderator, 4094 Posts

3 September 2008 at 4:13am

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

Community Member, 244 Posts

3 September 2008 at 9:58am

Edited: 03/09/2008 9:58am

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

Forum Moderator, 4094 Posts

4 September 2008 at 5:08am

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