Make the validation engine compatible with UI datepicker
Currently the blur event get in conflict with the jquery UI action making the validation of date pretty weird
The ValidationEngine with a datepicker
Using a datepicker with the engine is problematic because the validation is binded to the blur event. since we lose the focus before any data is entered in the field it creates a weird bug. Fortunately we implemented a fix where we use a delay when a datepicker is binded.
To use this mode you need to add the class datepicker to your input, like this:
<input type="text" id="req" name="req" class="validate[required] text-input datepicker" value="">
The validation message appears when I click on any button of the datepicker's calendar.
I Think a better solution for this issue is to register listener for the datepicker events, maybe something like this: $('.datepicker').datepicker({ onSelect: function(dateText, inst) { /* validation here */ } });
http://stackoverflow.com/questions/1814292/jqueryui-datepicker-fires-inputs-blur-before-passing-date-avoid-workaround http://stackoverflow.com/questions/2607397/jquery-validationengine-plugin-custom-callback-for-datepicker-input-fields
Thanks, not a simple issue, I will see how I can ameliorate the datepicker compatibility
my solution for now is comment out the bind and live code in validationEngine.js file and do the validation onClose event of datepicker and it works fine for me. jquery.ValidationEngine.js
if (!options.binded) {
if (options.bindMethod == "bind"){
...
//form.find("[class*=validate][class*=datepicker]").bind(options.validationEventTrigger,{"delay": 300}, methods._onFieldEvent);
...
} else if (options.bindMethod == "live") {
...
//form.find("[class*=validate][class*=datepicker]").live(options.validationEventTrigger,{"delay": 300}, methods._onFieldEvent);
...
}
options.binded = true;
}
my datepicker:
$("#inputDate").datepicker(
{
beforeShow: function (input) { $('#form1').validationEngine('hide'); },
onClose: function (dateText, inst)
{
$('#form1').validationEngine('validateField', '#inputDate')
}
});
Adding a "datepicker" class is not necessary, jQuery UI does all the required DOM manipulation for us. I played around a bit, but I did not find a solution that fits all needs. Maybe this snipped helps anyway:
/**
* Is the current field a datepicker, and is it open
*
* @param {jqObject}
* field
* @return true if field has a open datepicker
*/
_hasOpenDatepicker: function(field) {
if (!field.hasClass('hasDatepicker'))
return false;
if (jQuery('#ui-datepicker-div').css('display') != 'block')
return false;
return true;
},
As soon as jQuery UI supports a binding of "onClose" to the function stack of a initialised object I could offer a working solution.
My solution that helped me: $("#date").datepicker( { beforeShow: function () { $("#date").removeAttr("data-validation-engine"); } });