Skip to content

Commit

Permalink
Merge pull request #1045 from DTS-STN/185041-MaxLength
Browse files Browse the repository at this point in the history
185041 - Year setting a max length
  • Loading branch information
MarcoGoC authored Apr 18, 2024
2 parents d8545cd + 16f1ab0 commit 8d95610
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/Forms/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export const DatePicker: React.FC<DatePickerProps> = (props) => {
const matcher = new RegExp(/[\D]/g)
e.target.value = e.target.value.replaceAll(matcher, '')
}
const maxLength = (e) => {
e.target.value =
e.target.value.length > 4 ? e.target.value.slice(0, 4) : e.target.value
}

const monthValues = Array.from({ length: 12 }, (_, i) => (i + 1).toString())

Expand All @@ -55,6 +59,7 @@ export const DatePicker: React.FC<DatePickerProps> = (props) => {

const _onYearChange = (e) => {
restrictNonNumbers(e)
maxLength(e)
props.onYearChange(e)
}

Expand Down

0 comments on commit 8d95610

Please sign in to comment.