Skip to content
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

datetime alias: autofill year with currentyear #2266

Closed
DeepaSunil86 opened this issue Jan 24, 2020 · 31 comments
Closed

datetime alias: autofill year with currentyear #2266

DeepaSunil86 opened this issue Jan 24, 2020 · 31 comments

Comments

@DeepaSunil86
Copy link

No description provided.

@DeepaSunil86 DeepaSunil86 changed the title Input Mask is not working with year 2020 and i Input Mask is not working with year 2020 and it results 20yy Jan 24, 2020
@DeepaSunil86
Copy link
Author

Please help me to solve this issue. the Mask is not working for year 2020 when we input 20 in the date field. The mask input is dd/mm/yyyy.

@RobinHerbots
Copy link
Owner

@DeepaSunil86,

Which version of Inputmask are you using?

@DeepaSunil86
Copy link
Author

i am using Version: 3.1.63. i tried with latest solution too and the issue still exists.

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

Can you create a jsfiddle with an example. Does this also occur on the demo page?

@DeepaSunil86
Copy link
Author

yes i can see the same issue in the demo page.

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

Can you provide some more info as I cannot reproduce the problem.

Which browser & os are you using?

@DeepaSunil86
Copy link
Author

Internet Explorer 11 and Windows 8.1. The Input Mask version i am using is 3.1.63. The issue we faced for 2020 years, when we input 20, the mask is not auto populate with 2020. The configured Min Year is 1900 and Max is 2099 .

@RobinHerbots
Copy link
Owner

RobinHerbots commented Jan 27, 2020

@DeepaSunil86 ,

I think I start to understand the issue. You mean there is no autofill for the year?

What is your input? Can you give an example.

@RobinHerbots
Copy link
Owner

Internet Explorer 11 and Windows 8.1. The Input Mask version i am using is 3.1.63. The issue we faced for 2020 years, when we input 20, the mask is not auto populate with 2020. The configured Min Year is 1900 and Max is 2099 .

How can I determine if the min value is 1900 and the maxvalue is 2099 that the user wants to type 2020 when he enters 20 and not 2019 or 2021, ...

@DeepaSunil86
Copy link
Author

The issue seems here , previously i made a small change in the isInYearRange function comes under jquery.inputmask.date.extensions.js

isInYearRange: function(chrs, minyear, maxyear) {
if (isNaN(chrs)) return !1;

            var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length))), 
			enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length)));						
			
			 **return (isNaN(enteredyear) ? !1 : enteredyear > minyear && maxyear > enteredyear) || 
			 (isNaN(enteredyear2) ? !1 : enteredyear2 > minyear && maxyear >= enteredyear2);				              
        }**

in the return statement so that it worked for 2019(maxyear >= enteredyear) changed to ( maxyear > enteredyear). I dont know for 2020. The Mask is not applying for 20 resulting 20yy also it is not triggering any incomplete event when it fails to do so.

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

I only go forward with version 5.x. Do you have a suggestion about how I can autocomplete the year.

@DeepaSunil86
Copy link
Author

can you able to share the code for auto mask complete for year 2020 in 5.x, if so it will be a great help for me. Thanks in advance.

@DeepaSunil86
Copy link
Author

I am stuck with this for few days with no luck

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

There is no autocomplete logic on the year. And I don't see it possible, besides a limited autocomplete based on the min, max value. Or do you have some suggestion?

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

A solution would be to always suggest the current year and allow to overwrite the value.

So entering 01/28/20 would show like 01/28/2020
Leaving the field completes it like 01/28/2020
Continue typing ex 21 would result in 01/28/2021

What do you think?

@DeepaSunil86
Copy link
Author

yes correct and the solution i need to be like this.

@RobinHerbots RobinHerbots changed the title Input Mask is not working with year 2020 and it results 20yy datetime alias: autofill year with currentyear Jan 27, 2020
@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

Have a try with version 5.0.4-beta.7

@DeepaSunil86
Copy link
Author

Could you please give me an example code to use this. I was trying with version 3.x and when i tried with 5.x the autofillcompletion for datetime is not working for me.

@RobinHerbots
Copy link
Owner

@DeepaSunil86
Copy link
Author

Hi @RobinHerbots,
i just tried your link but looks this is not what i am looking for. I gave an example below in 3.x.
https://codepen.io/DeepaSunil86/pen/zYxXXrp.

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

Your codepen doesn't seem to be working.

@DeepaSunil86
Copy link
Author

@RobinHerbots
Copy link
Owner

RobinHerbots commented Jan 28, 2020

@DeepaSunil86 ,

Ok, the first case can be better but then you should specify a min value like 01/01/2019. There is still some polishing needed. But 010120 should be ok.

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

https://codepen.io/robinherbots/pen/eYmoLJG
I added a default minvalue, like in version 3.x, which can be overruled by specifying the min option.

@RobinHerbots
Copy link
Owner

@DeepaSunil86,

Can this be closed?

@DeepaSunil86
Copy link
Author

Hi,
Yes, i just customized the incomplete event and made this. Thanks for the support.

Regards,
Deepa.

@kaushik3pg
Copy link

kaushik3pg commented Sep 10, 2021

Hi Robin,

I am encountering a problem here which is as follows,
so, when I enter a date like 12/12/20 it autofills the rest of the year as 21, which makes the entire date to be 12/12/2021. However, we are using this as a date of birth entry, so autocompleting the year every time a user enters 20 to 2021 makes a bad user experience. Is there a way by which a user enters 12/12/20 and autocompletion does not take effect.

Thanks for your time.

Edit : I checked your codepen : https://codepen.io/robinherbots/pen/eYmoLJG and same is happening there as well. Try entering 121220 in the field. Actual result : 12/12/2021 , what I am expecting : 12/12/20 with cursor on the third character of yyyy.

@RobinHerbots
Copy link
Owner

@DeepaSunil86 ,

You can disable this behavior by using the prefillYear option.
You can read about in the readme for the datetime alias.

@RobinHerbots
Copy link
Owner

@kaushik3pg ,

See my previous comment 😁

@kaushik3pg
Copy link

Ah prefillYear is the one. Thank you so much Robin. It worked perfectly well.

@pks28
Copy link

pks28 commented Jan 12, 2022

Hi @RobinHerbots
I am using inputmask v5.0.7 in angular11 and therefore using typed definitions @type/inputmask v5.0.1 which is latest but seems like the definition for prefillYear is not updated there. Can you please look into this. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants