Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions app/javascript/packs/form-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { loadPolyfills } from '@18f/identity-polyfill';
/** @typedef {{t:(key:string)=>string, key:(key:string)=>string}} LoginGovI18n */
/** @typedef {{LoginGov:{I18n:LoginGovI18n}}} LoginGovGlobal */

const PATTERN_TYPES = ['personal-key'];

const snakeCase = (string) => string.replace(/[ -]/g, '_').replace(/\W/g, '').toLowerCase();

/**
* Given a submit event, disables all submit buttons within the target form.
*
Expand Down Expand Up @@ -60,14 +56,6 @@ function checkInputValidity(event) {
if (input.validity.valueMissing) {
input.setCustomValidity(I18n.t('simple_form.required.text'));
input.setAttribute('data-form-validation-message', '');
} else if (input.validity.patternMismatch) {
PATTERN_TYPES.forEach((type) => {
if (input.classList.contains(type)) {
// i18n-tasks-use t('idv.errors.pattern_mismatch.personal_key')
input.setCustomValidity(I18n.t(`idv.errors.pattern_mismatch.${snakeCase(type)}`));
input.setAttribute('data-form-validation-message', '');
}
});
}
}

Expand Down
2 changes: 0 additions & 2 deletions config/locales/idv/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ en:
incorrect_password: The password you entered is not correct.
mail_limit_reached: You have requested too much mail in the last month.
pattern_mismatch:
personal_key: 'Please enter your personal key for this account. Example:
ABC1-DEF2-G3HI-J456'
ssn: 'Your Social Security Number must be entered in as ###-##-####'
zipcode: Enter a 5 or 9 digit ZIP code
unsupported_otp_delivery_method: Select a method to receive a code.
Expand Down
2 changes: 0 additions & 2 deletions config/locales/idv/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ es:
incorrect_password: La contraseña que ingresó no es correcta.
mail_limit_reached: Usted ha solicitado demasiado correo en el último mes.
pattern_mismatch:
personal_key: 'Introduzca su clave personal para esta cuenta. Ejemplo:
ABC1-DEF2-G3HI-J456'
ssn: 'Su número de Seguro Social debe ser ingresado como ### - ## - ####'
zipcode: Ingresa un código postal de 5 o 9 dígitos
unsupported_otp_delivery_method: Seleccione una manera de recibir un código.
Expand Down
2 changes: 0 additions & 2 deletions config/locales/idv/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ fr:
incorrect_password: Le mot de passe que vous avez inscrit est incorrect.
mail_limit_reached: Vous avez demandé trop de lettres au cours du dernier mois.
pattern_mismatch:
personal_key: 'Veuillez inscrire votre clé personnelle pour ce compte, par
exemple : ABC1-DEF2-G3HI-J456'
ssn: 'Votre numéro de sécurité sociale doit être inscrit de cette façon :
###-##-####'
zipcode: Entrez un code postal à 5 ou 9 chiffres
Expand Down
21 changes: 0 additions & 21 deletions spec/javascripts/packs/form-validation-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ describe('form-validation', () => {
<form>
<input type="text" aria-label="not required field">
<input type="text" aria-label="required field" required class="field">
<input type="text" aria-label="format" pattern="\\\\A\\\\d{5}(-?\\\\d{4})?\\\\z">
<input type="text" aria-label="format unknown field" pattern="\\\\A\\\\d{5}(-?\\\\d{4})?\\\\z" class="field">
<input type="text" aria-label="format field" pattern="(?:[a-zA-Z0-9]{4}([ -])?){3}[a-zA-Z0-9]{4}" class="field personal-key">
</form>`;

initialize(document.querySelector('form'));
Expand All @@ -71,24 +68,6 @@ describe('form-validation', () => {
expect(requiredField.validationMessage).to.equal('simple_form.required.text');
await userEvent.type(requiredField, 'a');
expect(notRequiredField.validationMessage).to.be.empty();

const format = screen.getByLabelText('format');
await userEvent.type(format, 'a');
expect(format.validationMessage).to.not.be.empty.and.not.match(
/^idv\.errors\.pattern_mismatch\./,
);

const formatUnknownField = screen.getByLabelText('format unknown field');
await userEvent.type(formatUnknownField, 'a');
expect(formatUnknownField.validationMessage).to.not.be.empty.and.not.match(
/^idv\.errors\.pattern_mismatch\./,
);

const formatField = screen.getByLabelText('format field');
await userEvent.type(formatField, 'a');
expect(formatField.validationMessage).to.equal('idv.errors.pattern_mismatch.personal_key');
await userEvent.type(formatField, 'aaa-aaaa-aaaa-aaaa');
expect(formatField.validationMessage).to.be.empty();
});

it('resets its own custom validity message on input', () => {
Expand Down