Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Javascript: Behaviour.js

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

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

Page: 1
Go to End
Author Topic: 2300 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    Javascript: Behaviour.js Link to this post

    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...

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Javascript: Behaviour.js Link to this post

    > 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.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Javascript: Behaviour.js Link to this post

    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..

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Javascript: Behaviour.js Link to this post

    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)

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Javascript: Behaviour.js Link to this post

    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?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Javascript: Behaviour.js Link to this post

    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).

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Javascript: Behaviour.js Link to this post

    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?

  • tareq1
    Avatar
    Community Member
    2 Posts

    Re: Javascript: Behaviour.js Link to this post

    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

    2300 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.