Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Validation on forms using JS

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 2580 Views
  • wakes
    Avatar
    Community Member
    7 Posts

    Re: Validation on forms using JS Link to this post

    You can do a Requirements::block(...) to prevent a file from being loaded, then add your file - you'll have to copy whole file though.

  • Elemental
    Avatar
    Community Member
    8 Posts

    Re: Validation on forms using JS Link to this post

    so should I block the JS file that is being called in sapphire/javascript/?

    surely there is another way to change this error handling in javascript?

  • wakes
    Avatar
    Community Member
    7 Posts

    Re: Validation on forms using JS Link to this post

    Try blocking the script, then in setting up Requirements re-add script and then add your own script with a custom 'validationError' function which could change functionality. If you manually add them I believe it keeps the correct order, and they are 'global' functions so latest will override previous.

    The current function appends a span with class "message required" to the parent element of the field with the "<field-name> is required" message. Instead change the function to change the field to, e.g. a red border (or the parent element).

    You could do this with CSS selector on the span with "message required" :prev type selector (and set the span itself to display: none) but this probably doesn't work on many browsers.

    You may need to block the default CSS and add your own/override styles where applicable too.

  • Elemental
    Avatar
    Community Member
    8 Posts

    Re: Validation on forms using JS Link to this post

    Thanks guys, I got it solved.

    I had to do the block and then include my file as you guys mentioned.

    However my JS file had to have the same content as the sapphire file and then I could override the function.

    here is the code that worked:

    Requirements::block('sapphire/javascript/Validator.js');
    Requirements::javascript('mysite/javascript/ValidatorExtension.js');

    thanks

    Elemental
    http://www.elemental.co.za
          

  • brokemeister
    Avatar
    Community Member
    30 Posts

    Re: Validation on forms using JS Link to this post

    Hi!
    What about the changes in the JS-File you did?

    2580 Views
Page: 1 2
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.