Support blur on datepicker in vc creation
Change-Id: If404dadc26b18900d4366287e9fd5e8e21c88088
diff --git a/dev/js/src/datepicker.js b/dev/js/src/datepicker.js
index 8ae5267..fe9e97d 100644
--- a/dev/js/src/datepicker.js
+++ b/dev/js/src/datepicker.js
@@ -36,6 +36,7 @@
return Object.create(this)._init();
},
+
// Init datepicker
_init : function () {
this._selected = [];
@@ -93,6 +94,10 @@
this._click = cb;
},
+
+ input : function () {
+ return this._input;
+ },
/**
* Show the datepicker.
@@ -120,10 +125,40 @@
(today.getMonth() + 1));
// Append all helpers
- this._element.appendChild(this._monthHelper());
- this._element.appendChild(this._yearHelper());
- this._element.appendChild(this._dayHelper());
- this._element.appendChild(this._stringHelper());
+ e.appendChild(this._monthHelper());
+ e.appendChild(this._yearHelper());
+ e.appendChild(this._dayHelper());
+ this._input = e.appendChild(this._stringHelper());
+
+ // Always focus
+ e.addEventListener(
+ 'mousedown',
+ function (ev) {
+ this._inField = true
+ }.bind(this)
+ );
+
+ e.addEventListener(
+ 'mouseup',
+ function (ev) {
+ this._inField = false;
+ this._input.focus();
+ }.bind(this)
+ );
+
+ this._input.addEventListener(
+ 'blur',
+ function (ev) {
+ if (!this._inField) {
+ if (this.fromString(this._input.value)) {
+ this.store();
+ };
+ };
+ ev.halt();
+ }.bind(this)
+ );
+
+ this._input.focus();
return this._element;
},
diff --git a/dev/js/src/vc/doc.js b/dev/js/src/vc/doc.js
index 67bf37a..87b7057 100644
--- a/dev/js/src/vc/doc.js
+++ b/dev/js/src/vc/doc.js
@@ -441,7 +441,7 @@
// Show datepicker
if (this.type() === 'date') {
var dp = KorAP._vcDatePicker;
- dp.fromString(v)
+ dp.fromString(v);
// Todo: change this
dp.onclick(function (selected) {
@@ -467,16 +467,7 @@
this._valueE
);
- dpElem.focus();
- /*
- dpElem.addEventListener('blur', function (e) {
- e.halt();
-
- // Remove datepicker
- // TODO: If focus is not set to string input
- that._element.removeChild(this);
- });
- */
+ dp.input().focus();
}
else {
var regex = this.type() === 'regex' ? true : false;