Skip to content

Conversation

@pragatheeswarans
Copy link
Contributor

Issue:

When the locale of the DatePickerInput component is set to "de" (German), the functionality to add an automatic date separator ("." in the case of the German locale) is broken. Instead of appending a dot to the first two characters entered, the input gets changed to a single dot. Subsequently, any numbers entered are concatenated without the proper separator.

Solution:

I found the usage of the RegExp constructor to create regular expressions. One of the supported date separator is . (dd.mm.yyyy). The dot character is a metacharacter in regular expressions which needs to be escaped if it is being passed into the RegExp constructor. In this code block, it was not escaped. Hence the code

new RegExp('.', 'g')

yielded a different regex than the expected one.

Fixes DatePickerInput component breaks automatic date separator when setting locale to "de"

@pragatheeswarans pragatheeswarans marked this pull request as ready for review June 20, 2023 13:21
}

function escapeForRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dot is the only special character that is used here for splitCharacter. I added all special characters here because maybe this can be abstracted to util in the future and used in other places. If you prefer to have only ., I can change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iM-GeeKy iM-GeeKy requested a review from RichardLindhout June 20, 2023 13:36
@RichardLindhout RichardLindhout merged commit df50c8b into web-ridge:master Jun 22, 2023
@RichardLindhout
Copy link
Member

@pragatheeswarans I'm don't fully understand of what is going on but LGTM!

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

Successfully merging this pull request may close these issues.

DatePickerInput component breaks automatic date separator when setting locale to "de"

2 participants