Skip to content

Commit

Permalink
fix: only numbers allowed in year of birth (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
iajaymk authored Nov 28, 2023
1 parent c19e93c commit f5847c1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions frontend/app/components/profile/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,21 @@ export default class ProfileComponent extends Component {
});
}
}

@action
setBirthday(e: Event) {
const key = e.key;
const allowedKeys = [
'Backspace',
'Delete',
'Tab',
'Enter',
'ArrowLeft',
'ArrowRight',
];
const isValid = allowedKeys.includes(key) || !isNaN(key as any);
if (!isValid) {
e.preventDefault();
}
}
}
1 change: 1 addition & 0 deletions frontend/app/components/profile/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
minlength="4"
maxlength="4"
pattern="[0-9]{4}"
{{on "keydown" this.setBirthday}}
{{on "change" (fn this.onInput "birthday")}}
@warning={{this.warningErrorDate}}
@model={{this.user}}
Expand Down
18 changes: 18 additions & 0 deletions frontend/app/components/registration-form/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,22 @@ export default class RegistrationFormComponent extends LoginFormComponent {
setAgreedStatus(e: Document & any) {
this.agreed = e.target.checked;
}

@action
setBirthday(e: Event) {
const key = e.key;
const allowedKeys = [
'Backspace',
'Delete',
'Tab',
'Enter',
'ArrowLeft',
'ArrowRight',
];
const isValid = allowedKeys.includes(key) || !isNaN(key as any);
if (!isValid) {
e.preventDefault();
}

}
}
1 change: 1 addition & 0 deletions frontend/app/components/registration-form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@placeholder={{t "registration_form.birthday_placeholder"}}
@model={{this}}
@name="birthday"
{{on "keydown" this.setBirthday}}
/>
</div>
<div class="mb-4">
Expand Down

0 comments on commit f5847c1

Please sign in to comment.