From 676148ba94f436565be2399f66d7e98c03450407 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 9 Sep 2016 15:46:13 +0200 Subject: [PATCH] Implement client-side validation check for date_duration in order to catch check the validity right after entry before submit. --- api/js/etemplate/et2_widget_date.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/api/js/etemplate/et2_widget_date.js b/api/js/etemplate/et2_widget_date.js index 32fb2c3a3a..7e5d23b6d2 100644 --- a/api/js/etemplate/et2_widget_date.js +++ b/api/js/etemplate/et2_widget_date.js @@ -743,7 +743,30 @@ var et2_date_duration = (function(){ "use strict"; return et2_date.extend( { this.format = jQuery(""+this.time_formats["m"]+"").appendTo(this.node); } + var self = this; + // seems the 'invalid' event doesn't work in all browsers, eg. FF therefore + // we use focusout event to check the valifdity of input right after user + // enters the value. + this.duration.on('focusout', function(){if(!self.duration[0].checkValidity()) return self.duration.change();}); }, + + /** + * Clientside validation + * + * @param {array} _messages + */ + isValid: function(_messages) + { + var ok = true; + // if we have a html5 validation error, show it, as this.input.val() will be empty! + if (this.duration && this.duration[0] && this.duration[0].validationMessage && !this.duration[0].validity.stepMismatch) + { + _messages.push(this.duration[0].validationMessage); + ok = false; + } + return this._super.apply(this, arguments) && ok; + }, + attachToDOM: function() { var node = this.getInputNode(); if (node)