mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-18 00:09:06 +01:00
LSformElement:📅 Make today btn working even if input is empty
This commit is contained in:
parent
052882eb49
commit
e4ca5bbf71
1 changed files with 14 additions and 2 deletions
|
@ -91,12 +91,18 @@ var LSformElement_date_field = new Class({
|
||||||
},
|
},
|
||||||
|
|
||||||
onTodayBtnClick: function() {
|
onTodayBtnClick: function() {
|
||||||
if (this.input.value) {
|
if (this.input.value && this.params.time) {
|
||||||
|
// Date & time already defined: just change date and leave same time
|
||||||
|
|
||||||
|
// Parse current value
|
||||||
var cur = Date.parse(this.input.value,this.params.format);
|
var cur = Date.parse(this.input.value,this.params.format);
|
||||||
if (cur == null) {
|
if (cur == null) {
|
||||||
var cur = Date.parse(this.input.value);
|
// On fail, try to parse value without specify format
|
||||||
|
cur = Date.parse(this.input.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur) {
|
if (cur) {
|
||||||
|
// Current value parsed, clone it and change date
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
var today = cur.clone();
|
var today = cur.clone();
|
||||||
today.set({
|
today.set({
|
||||||
|
@ -106,8 +112,14 @@ var LSformElement_date_field = new Class({
|
||||||
});
|
});
|
||||||
this.input.value = today.format(this.params.format);
|
this.input.value = today.format(this.params.format);
|
||||||
this.input.fireEvent('change');
|
this.input.fireEvent('change');
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
LSdebug("onTodayBtnClick(): fail to parse current input value => use current date");
|
||||||
}
|
}
|
||||||
|
this.input.value = new Date().format(this.params.format);
|
||||||
|
this.input.fireEvent('change');
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
clearValue: function() {
|
clearValue: function() {
|
||||||
|
|
Loading…
Reference in a new issue