262
Views
11
Comments
Solved
Year in date input is 6 characters long
Question
Application Type
Reactive

In reactive I have a input with type date. When typing a date, it is possible to type 6 characters for the year.

Someone know how to solve this issue?

Thx

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Lander,

At least in Chrome, it works when setting the max date to something with four years:

I can then type in only four digits for the year.

2019-03-08 13-21-38
Lander De Wulf

Wow so easy (if you know it) :-)

Big Thanks

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
2022-07-11 14-05-36
Jeroen Barnhoorn

In case someone (like myself) stumbles across this in the future: for a DateTime field you can use max="9999-12-31T23:59", instead.

2022-10-18 07-32-49
Randall Jodache Chetty

Thanks for sharing 

2024-04-19 08-26-30
syerasyl

Hi 
Briliant solution, thanks.
But I have issue with year limit
I thought max = "2100-12-31" will work, but I still can enter any number >= 9999
Looking for anykind of suggestion or advice :-)

Best Regards

Sera)

2021-09-30 18-38-59
Nuno Ricardo Rodrigues

Hello Lander De Wulf,

I supposed that you are using an input with a variable type Date, right? That is the default behaviour from the browser.

You can use Javascript, to remove the extra numbers after you insert more then 4, but if you made a "long press" on a number you will see for some seconds the all numbers before the Javascript erase the value.

Best Regards,

Nuno R

2025-09-29 11-10-28
José Alexandre dos Santos

Hi Lander,


You can limit the input length using Jquery.

don't forget to add this script to your libraries and reuse it instead of add it directly to your WB or Screen:

The input parameter of the script should be your input name and it should look something like this:

//Script stat ################

var max_chars = 10; //Max Characters number

$('#" + YourInputName.Id + "').keydown( function(e){

    if ($(this).val().length >= max_chars) { 

        $(this).val($(this).val().substr(0, max_chars));

    }

});

$('#" + YourInputName.Id + "').keyup( function(e){

    if ($(this).val().length >= max_chars) { 

        $(this).val($(this).val().substr(0, max_chars));

    }

});

//Script End ################

Note: you need to replace YourInputName, with your actual Input name (give it a name if it has not one already)

You can also define another script input parameter and replace the number of characters into a dynamic way to reused it in the future to other different lenght inputs that you want to limit.


Cheers,

JS.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Lander,

At least in Chrome, it works when setting the max date to something with four years:

I can then type in only four digits for the year.

2019-03-08 13-21-38
Lander De Wulf

Wow so easy (if you know it) :-)

Big Thanks

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
2022-07-11 14-05-36
Jeroen Barnhoorn

In case someone (like myself) stumbles across this in the future: for a DateTime field you can use max="9999-12-31T23:59", instead.

2022-10-18 07-32-49
Randall Jodache Chetty

Thanks for sharing 

2024-04-19 08-26-30
syerasyl

Hi 
Briliant solution, thanks.
But I have issue with year limit
I thought max = "2100-12-31" will work, but I still can enter any number >= 9999
Looking for anykind of suggestion or advice :-)

Best Regards

Sera)

2021-09-30 18-38-59
Nuno Ricardo Rodrigues

Hello Lander De Wulf

I think the solution presented by Kilian Hekhuis, is nice, a have tried on other recent browsers and work. The one presented by José Santos, I think will work also but is better to convert to vanilla JS, because we don't need jQuery.

Best Regards,

Nuno R


2023-07-18 09-00-28
Prashant Raghuwanshi

@Kilian Hekhuis 

thank you its working.

2024-04-19 08-26-30
syerasyl
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.