Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Option to leave out javascript validation

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: 2701 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    Option to leave out javascript validation Link to this post

    Currently there doesn't seem to be a way to leave out javascript validation without hacking into the validator.php file, not a problem for me but not so good for upgrading.

    Doing on Requirements::clear(..) doesn't help, as the js will always be included when using 'new requiredfield'.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Option to leave out javascript validation Link to this post

    the trick is to clear requirements as close to rendering as possible:
    in your case of form-validation, this would be YourCustomFormClass->forTemplate()

    but you're right, there should be a switch to disable client-side validation...

  • Blackdog
    Avatar
    Community Member
    156 Posts

    Re: Option to leave out javascript validation Link to this post

    dio5, did you sort this out and get Requirements::clear() to work correctly?

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Option to leave out javascript validation Link to this post

    Perhaps we should add a couple of useXXValidation() methods on the form, to turn this on / off?

    $form->useJavascriptValidation(false);
    $form->usePHPValidation(false);

    If we did that, the best thing would be to have a FormField::includeJavascriptValidation() method that was called on each Field as part of the form rendering, if javascript validation was selected. It would be a bit of a refactoring, but it would put the responsibility for deciding whether to include javascript validation in the hands of the Form object, which is more appropriate than in the individual form fields.

    If we can make a patch for this on trunk, then Dio5 / Blackdog can apply it to their own branches before the next release.

  • Blackdog
    Avatar
    Community Member
    156 Posts

    Re: Option to leave out javascript validation Link to this post

    Dio5, I never could get the clear() to work even if I targeted the individual files.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Option to leave out javascript validation Link to this post

    Sam, that sounds like a good idea.

    I managed to work around this with subclassing RequiredFields and returning empty javascriptvalidation functions. - i e overriding those functions in Validator that make the js validation with a blank method.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Option to leave out javascript validation Link to this post

    W/regards Sam's comment, I'd be particularly interested in the ability to override any SS generated javascript with my own.

    For example, I use jQuery, so it totally sucks to have prototype imported and used to validate forms when there is an excellent jQuery Validitor plugin that is very easy to template and would add very little overhead to my existing pages. If the hooks were available, devs could produce jQuery/Mootools/YUI ports to perform these common tasks.

    If someone is already doing this, or there is a workable solution already, please let me know. Otherwise I'm interesting in helping produce such a framework if someone wants to point me in the right direction.

    Cheers!

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