Skip to content

Commit

Permalink
Merge branch 'fix/PN-10282' of github.com:pagopa/pn-frontend into fix/P…
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahDonvito committed Mar 29, 2024
2 parents 9b11e50 + 6493a30 commit a6710c4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/pn-commons/src/components/CodeModal/CodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ const CodeInput = ({ initialValues, isReadOnly, hasError, onChange, onInputError
changeInputValue(value, index);
return;
}
value = value.replace(/[^a-zA-Z\d]/g, '');
// remove from value those characters that aren't letters neither numbers
value = value.replace(/[^a-z\d]/gi, '');
if (value !== '') {
// case maxLength 2
if (value.length > 1) {
Expand All @@ -125,10 +126,11 @@ const CodeInput = ({ initialValues, isReadOnly, hasError, onChange, onInputError
event.preventDefault();
// eslint-disable-next-line functional/no-let
let pastedCode = event.clipboardData.getData('text');
pastedCode = pastedCode.replace(/[^a-zA-Z\d]/g, '');
pastedCode = pastedCode.replace(/[^a-z\d]/gi, '');
const maxLengthRequiredCode = pastedCode.slice(0, initialValues.length);
const values = maxLengthRequiredCode.split('');

// we create an array with empty values for those cases in which the copied values are less than required ones
// initialValues.length - values.length can be only >= 0 because of the slice of pastedCode
const emptyValues = new Array(initialValues.length - values.length).fill('');
setCurrentValues(values.concat(emptyValues));
focusInput(-1);
Expand Down

0 comments on commit a6710c4

Please sign in to comment.