Posted 14 November 2017, 12:21 pm EST
Hi,
Is there a way to provide wj-input-date with a custom parser? Like enter ‘x’ would parse to the current date.
Thanks,
Johnny
Forums Home / Wijmo / General Discussion
Posted by: johnny.su on 14 November 2017, 12:21 pm EST
Posted 14 November 2017, 12:21 pm EST
Hi,
Is there a way to provide wj-input-date with a custom parser? Like enter ‘x’ would parse to the current date.
Thanks,
Johnny
Posted 14 November 2017, 6:04 pm EST
Hi Johnny,
For this you need to handle keyDown event for control and set the value accordingly.
dateCtrl.hostElement.addEventListener("keydown", function(e){
// logic here and assign new date to dateCtrl.value
},true);
But this may conflict with default functionality for control. Hence,this is not recommended to apply custom parser.
~Manish
Posted 24 May 2018, 4:03 am EST
Hi Manish,
I was able to use the lostFocus event to parse the entered text and set the dataCtrl.value.
dataCtrl.lostFocus.addHandler(function (control) {
dateCtrl.value = customParser(control._oldText); // _oldText is the entered text
});
But with the latest version, for some reason the control is parsing the value and then the lostFocus event fires. When the dateCtrl.value changes before the lostFocus event, the dateCtrl._oldText is no longer what I entered. Then the next time, on the same field, if I enter the text again and leave the field, the lostFocus event fires first. Then the order of valueChanged and lostFocus event firing flip flops.
Do you know what determines the order of the events? Because it doesn’t seem to be consistent. We really need the lostFocus event fire first so we use the text that the user entered so we can set the dateCtrl.value correctly.
Regards,
Johnny
Posted 24 May 2018, 10:41 pm EST
Hi,
We are sorry, we are unable to replicate the issue at our end.
Here is the link for the sample used for testing at our end:
https://stackblitz.com/edit/js-ivo8aw?file=index.js
We are getting the _oldText as the entered value inside the lostFocus event handler.
Please have a look at the sample and let us know if we are missing something important to replicate the issue.
~Manish
Posted 25 May 2018, 8:26 am EST
Hi Manish,
Please try using the steps below.
Regards,
Johnny
Posted 27 May 2018, 7:49 pm EST - Updated 3 October 2022, 11:29 am EST
Hi,
We tried the mentioned steps but we are still unable to replicate the issue at our end.
Please have a look at the attached gif and let us know if there is anything else we need to do for replicating the issue.
~Manish