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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

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

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

Javascript: Behaviour.js


Go to End


8 Posts   2835 Views

Avatar
dio5

Community Member, 501 Posts

24 September 2007 at 5:43am

2 more questions on javascript:

1) How can I turn off jsvalidation that is part of the standard contactform? I noticed there's some 255k js involved, a bit much for a simple contact form... so I could better use my own validation...

2) Where can I read about this behaviour.js-file, how to use it for event-handling.. etc.. ? If in some cases do keep SS's way of validation and included javascript, I don't want to use the library I'm used to use (YUI). It's a bit stupid to include 2 libraries that probably can handle the same stuff...

Avatar
Ingo

Forum Moderator, 801 Posts

24 September 2007 at 1:33pm

Edited: 24/09/2007 1:36pm

> I noticed there's some 255k js involved, a bit much for a simple contact form
fair point. the key here is enabling gzip-compression on the server, then its only a fraction of that size.

> Where can I read about this behaviour.js-file
it developed pretty much in parallel to the popular behaviour-script (http://bennolan.com/behaviour), but included some SS-specific stuff like Class-handling.
unfortunately its not fully documented, but you can have a look at the wiki[url].

customizing javascript-validation to use your own javascript is pretty easy: just selectively clear requirements in the init()-method of your controller and add your own stuff ([url=http://doc.silverstripe.com/doku.php?id=requirements]http://doc.silverstripe.com/doku.php?id=requirements).

class Page_Controller extends ContentController() {
  function init() {
    parent::init();
    Requirements::clear('jsparty/prototype.js');
    Requirements::javascript('mysite/javascript/yui.js');
    // ...
  }
}

of course you have to attach your own javascript-behaviour to the form/formfields this way.
the silverstripe-specific php-validation will still kick in though.

Avatar
dio5

Community Member, 501 Posts

25 September 2007 at 4:33am

Ok, thanks.

I actually want to know if there are some built-in functions/methods that can handle cross-browser issues such as event-handling and stuff..

With the YUI -library I can say for example:

YAHOO.util.Event.addListener(element, event, function)

It makes crossbrowser issues easy..

Avatar
Ingo

Forum Moderator, 801 Posts

25 September 2007 at 8:22am

hm, nothing "built-in" to silverstripe - we're mostly using external libraries, such as prototype.
see http://prototypejs.org/api (just be aware that the prototype.js included by default in silverstripe is a customized 1.4rc1, rather than the current 1.6)

Avatar
dio5

Community Member, 501 Posts

5 October 2007 at 2:37am

Ingo,

class Page_Controller extends ContentController() {
function init() {
parent::init();
Requirements::clear('jsparty/prototype.js');
Requirements::javascript('mysite/javascript/yui.js');
// ...
}
}

this approach doesn't seem to work when using 'new RequiredFields()'. It always seems to throw in the SS-javascript.

Any ideas of how to get that out?

Avatar
Ingo

Forum Moderator, 801 Posts

5 October 2007 at 6:50am

hm, your code looks ok. formfields are usually constructed after your init()-call, which means that the prototype-requirement could be re-added after clearing. there's no way in 2.1 to prevent this afaik - i've written a simple Requirements::block()-function in some internal sapphire-branch, but this hasn't been merged back yet.
you can try to clear requirements directly before rendering anything (or returning the form in your case).

Avatar
dio5

Community Member, 501 Posts

5 October 2007 at 7:02am

Yeah, I tried doing the clears right after the new requiredfields but that didn't do the trick either..

I'm afraid it is not possible.

I guess I'm probably going to end up leaving out requiredfields, and do the test on my form-save method myself.

I guess I still keep the SS- numeric and email validation anyway, no? I suppose the 'new requiredfields' only checks if there is a value, no matter which?

Avatar
tareq1

Community Member, 2 Posts

18 September 2008 at 6:42pm

Hi Sean,

I am doing Search page , so i m trying add your javascript code for onclick event but its not able to executing that code i did all the same process as u post in the Forum to Nicolaas reply.

Thanking you.

waiting for your reply.

Tareq :)