views:

168

answers:

0

I have some datePickers
I've customized these so they show only month and year
This is the code to create them

jQuery("input[name*='fechauso']").each(function() {
    jQuery(this).datepicker({
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'MM yy',
        constrainInput: true,
        showOn: 'button',
        buttonText: 'Seleccionar...',

        onClose: function(dateText, inst) { 
            var month = jQuery("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = jQuery("#ui-datepicker-div .ui-datepicker-year :selected").val();
            jQuery(this).datepicker('setDate', new Date(year, month, 1));
        }
    });
});

Now I've added a custom validator method (using plugin) to check this:

  • If user didn't select a date using the button, field is empty, so the custom validator method should fire. This doesn't happen.

Here is the custom validate method

jQuery.validator.addMethod("isEmpty", function(value, element) {
    return (value == '');
}, "Must select a date with the button besides control");

jQuery("#ct_2_fechauso").rules("add", { 
    required: "#campotilde_psico:checked", 
    isEmpty: true
});

The problem is that even if I select a date, it always ask me to select a date again. datePicker fields should be readonly