-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FSADT1-999] Add birth date to frontend (#643)
* feat: add a date input component Specially for date of birth. * refactor: extract date part component * fix: always revalidate day * feat: add the date of birth to the form * refactor: reuse enum DatePart * feat: add condition for displaying the birthdate * feat: add birthdate label * style: replace single-quote with double-quote * fix: disable the next button properly Replaces the types of event emmited and used to determine when to enable the next button. * fix: adjust validations and events * fix: issue after returning to the step containing the date * feat: add business validations * feat: apply text mask * feat: auto-move to next date part * feat: perform conditional validation * fix: revalidate everything on revalidate-bus * test: fill the birthdate field * feat: replace some messages * fix: prevent highlighting all parts on error * docs: improve code comment * fix: make complexity of regex linear Fixes the security risk pointed by sonarcloud. * refactor: move date part validations to props Moves from `DateValidator` to props for part-specific business validations.
- Loading branch information
1 parent
32c87c5
commit 72f549f
Showing
9 changed files
with
712 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
frontend/src/components/forms/DateInputComponent/DateInputPart.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script setup lang="ts"> | ||
// Carbon | ||
import '@carbon/web-components/es/components/text-input/index'; | ||
// Types | ||
import { DatePart } from "./common"; | ||
// Define the input properties for this component | ||
const props = defineProps<{ | ||
parentId: string; | ||
datePart: DatePart; | ||
selectedValue: string; | ||
enabled?: boolean; | ||
invalid: boolean; | ||
}>(); | ||
const emit = defineEmits<{ | ||
blur: [event: FocusEvent] | ||
input: [event: Event] | ||
}>(); | ||
const datePartName = DatePart[props.datePart]; | ||
const capitalizedDatePart = datePartName[0].toUpperCase() + datePartName.substring(1); | ||
const id = props.parentId + capitalizedDatePart; | ||
defineExpose({ | ||
id, | ||
}); | ||
const placeholders = { | ||
[DatePart.year]: "YYYY", | ||
[DatePart.month]: "MM", | ||
[DatePart.day]: "DD" | ||
}; | ||
const placeholder = placeholders[props.datePart]; | ||
const mask = "#".repeat(placeholder.length); | ||
</script> | ||
|
||
<template> | ||
<div class="input-group"> | ||
<div class="cds--text-input__label-wrapper"> | ||
<label :id="parentId + capitalizedDatePart + 'Label'" :for="id" class="cds-text-input-label"> | ||
{{ enabled ? capitalizedDatePart : null }} | ||
</label> | ||
</div> | ||
<cds-text-input | ||
v-if="enabled" | ||
:id="id" | ||
type="tel" | ||
:placeholder="placeholders[datePart]" | ||
:value="selectedValue" | ||
:disabled="!enabled" | ||
:invalid="invalid" | ||
@blur="(e) => emit('blur', e)" | ||
@input="(e) => emit('input', e)" | ||
:data-focus="id" | ||
:data-scroll="id" | ||
:data-id="'input-' + parentId + '-' + datePartName" | ||
v-shadow="4" | ||
v-masked="mask" | ||
/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum DatePart { | ||
year, | ||
month, | ||
day, | ||
}; |
Oops, something went wrong.