Jump to:

1975 Posts in 1305 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » datepicker and onselect

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

Page: 1
Go to End
Author Topic: 439 Views
  • mgale
    Avatar
    Community Member
    1 Post

    datepicker and onselect Link to this post

    Hello,

    I am using Silverstripe 2.4.3 and jquery for form validation, following the example here:
    http://www.ssbits.com/tutorials/2009/using-jquery-for-form-validation/

    I have all the JS files specified in my Page.ss and have added the following to my page:
    --snip--
    function init() {
          parent::init();
             
          Validator::set_javascript_validation_handler('none');
          Requirements::customScript('
    jQuery(document).ready(function() {
    jQuery("#Form_Form").validate({
    rules: {
    Paper: "required",
    NumberOfCopies: "required",
                   DateRequiredProduction: {
                      required : true,
                      date : true
                   }
    },
    messages: {
    Paper: "Please pick a paper type",
    NumberOfCopies: "My default is a million copies",
                   DateRequiredProduction: "Let me know the date so I can exceed your expectations"
    }
    });

    });
    ');      
             
       }
    --snip--

    Now form validation is working great so far with the exception of a DateField, if you enter a valid entry to start off then everything just works. If you do not enter a value in the field and trigger a validation error on submit. You need to select a date twice in order for the field to get validated.

    I believe is can be fixed by defining a callback in the onselect method and have it call my validate method?

    However I have tried several things to get that to work and so far none have been successful. I tried adding the following to the JS above:
    --snip--
    jQuery("#DateRequiredProduction").datepicker("option", "onSelect", function() {
                alert("this is test");
                });
    --snipe--

    But I just get:
    jQuery("#DateRequiredProduction").datepicker is not a function

    Any ideas?

    Thanks
    Michael

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