-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entering date with keyboard does not work ($50 bounty to fix) #231
Comments
Hey, i don't have a solution (yet), but I can offer you a possible workaround: Use a different model for the field and the set() method. Unfortunately, this prevents the validation of the field, so you have to set I know this is far from perfect but it might help you. Edit: see fiddle |
Oh and you might consider using the latest version, this seems related to #138 |
I have tried the latest version, but doesn't seem to fix the issue; see https://jsfiddle.net/sjordan/8bph57yh/ The code you proposed seems like a decent temporary solution, but as you wrote, it's just a workaround. I do thank you @kingjan1999 |
You seem to be missing the bigger problem, this is not yet compatible with all browser. Here are some clues to correct the problem: /* src/fields/core line:6 */
:value="value",
@input="value = $event.target.value", We directly use the input event to set the value, which is use as a value for the field. /* src/fields/core line:52 */
formatValueToField(value) {
if (value != null) {
let dt;
switch(this.schema.inputType){
case "date":
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
return fecha.format(dt, "YYYY-MM-DD");
case "datetime":
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
return fecha.format(dt, "YYYY-MM-DD HH:mm:ss");
case "datetime-local":
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
return fecha.format(dt, "YYYY-MM-DDTHH:mm:ss");
}
}
return value;
} If a formatValueToModel(value) {
if (value != null) {
let m;
switch (this.schema.inputType){
case "date":
m = fecha.parse(value, "YYYY-MM-DD");
if (m !== false) {
if (this.schema.format)
value = fecha.format(m, this.schema.format);
else
value = m.valueOf();
}
break;
case "datetime":
m = fecha.parse(value, "YYYY-MM-DD HH:mm:ss");
if (m !== false) {
if (this.schema.format)
value = fecha.format(m, this.schema.format);
else
value = m.valueOf();
}
break;
case "datetime-local":
m = fecha.parse(value, "YYYY-MM-DDTHH:mm:ss");
if (m !== false) {
if (this.schema.format)
value = fecha.format(m, this.schema.format);
else
value = m.valueOf();
}
break;
case "number":
return Number(value);
}
}
return value;
} Here, it is the other way, when the model is defined, we change the value of the field. While, it may not be directly causing problem in your example, if the code change for value->model, it need to change for model->value too. In the meantime, you are better of with @icebob can you take a look at this when you have the time ? Thanks |
I think I've found the issue (at least for this problem): fecha. Replacing fecha with moment.js (which handles the dates correctly) fixes the problem. |
@kingjan1999 Great work, but we are not using moment. It is way to big and not modular enough. |
I'm afraid there is no such option: fecha uses getFullYear() for YYYY, but getFullYear returns just 2 instead of 0002. Either we write a workaround by formatting the dates by ourselves or report the issue to fecha and wait for a fix. Oh, and no, it doesn't work in firefox (yet). I'm working on it. |
Maybe it's a good time to push this idea ? Can we use date-fns, instead of fetcha ? With this, would the problem be resolved ? I'm using date-fns in my project, I find it better than fectha. Since it is very modular, we can start to use it alongside fetcha and remove fetcha progressively. @kingjan1999 Thank you for your work, when you think you have something ready, don't forget to do a PR. |
dateFns.format(new Date(0002,1,11), 'YYYY-MM-DD') returns and dateFns.getYear(new Date(0002,1,11)) in But moment isn't perfect as well, if it should work in firefox, we have to limit the valid formats (if no dateformat is given already), otherwise moment will parse almost every number as a valid date by falling back to new Date() (unless you know a method how to detect if the user have finished his input). |
@kingjan1999 Great investigation so far! @kingjan1999, @lionel-bijaoui It's kind of like the return of the Y2K bug?! fetcha and date-fns interpret a year such as "02" as 1902 rather than 2002, for example? |
Well, the problem is that these fields are not yet compatible in all major browser and we try to fix the discrepancy with these lib. One fix that I see, would be to check if the year start with two 0 and is a 4 digit number. If that the case, we don't format or send the data to the model. The best way to deal with that would be to just send the data like it is. No format/getYear. Type Again, this choice depends on @icebob decision. |
Hi all, As @lionel-bijaoui said the main problem is that the html5 date fields are very browser dependent fields. We can't make a solution which will be good everyone. So in this case please copy the fieldInput.js and create a custom date field with the desired features. With |
@icebob Since
If someone want something different, they can just clone it and do their thing (conversions, etc.). That way, when all browser will be compatible with It is very easy to modify, we just delete lines 53->67 and 75->101 from Right now, this is kind of backward, since newer more capable browser have a penalty (a bug). |
@icebob Hello, my bounty offer has been open and hanging out there since June. If this issue is not going to be fixed, please close it and tag "won't fix", so that my bounty offer can be closed. Cheers |
Are there anybody? |
@sjordan1975 @icebob this should be solved with PR #360 |
@sjordan1975 Can you check it? |
Something still does not seem right. New fiddle Repro steps (as original): Load fiddle at URL in Chrome
I expect to get 10/31/2017; however, in my case I get 10/31/0017 |
@icebob Please mark this comment as "won't fix" so that my bounty can be closed. It's been over 6 months since I raised this issue and 2 weeks since I reported that the latest update seems to still have the issue. Thank you in advance |
I think we need to add more logic into the abstract field and date component. Something that detects html5 Date fields in chrome and other browsers that convert it from a standard text entry ... if detected, it never sets the field value while it has focus ... the main issue is the formatModeToField code that overwrites what’s your entering. The delay I added helps, if you type fast... but doesn’t solve the problem if you’re entering the values in slowly. Adding some “do not update field while has focus” logic will be useful for some other fields as well. |
I have a fiddle here: https://jsfiddle.net/sjordan/r81k8240/5/
When I try to enter a date using just the keyboard (tab and number pad) it does not work.
Repro steps:
I expect to get 10/31/2017; however, in my case I get 10/31/1907
However, doing the above steps with default HTML5 works; for example, perform the above steps with W3Schools test form: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_date
NOTE: I have placed a $50 bounty to get this fixed urgently: https://www.bountysource.com/issues/46214782-entering-date-with-keyboard-does-not-work
The text was updated successfully, but these errors were encountered: