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.

Form Questions /

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

datepicker and onselect


Go to End
Reply


686 Views

Avatar
mgale

Community Member, 1 Post

1 June 2012 at 3:25pm

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