Skip to content

Commit

Permalink
validate length of data constraints and employer statement on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
banders committed Nov 5, 2024
1 parent 4aa9451 commit ed9ddbf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
62 changes: 55 additions & 7 deletions frontend/src/components/InputForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,14 @@
<v-row>
<v-col>
<div class="text-body-1 font-weight-bold">
<label for="comments"> Employer Statement </label>
<label
for="comments"
:class="{
'text-error': isSubmit && !isEmployerStatementValid,
}"
>
Employer Statement
</label>
<v-tooltip
id="employer-statement-tooltip"
text="Please share any general information about your employer."
Expand Down Expand Up @@ -384,16 +391,31 @@
<RichTextArea
id="employerStatement"
v-model="comments"
placeholder="Maximum 4,000 characters"
:max-length="4000"
:placeholder="`Maximum ${employerStatementMaxLength} characters`"
:max-length="employerStatementMaxLength"
:error-message="
isSubmit && !isEmployerStatementValid
? `Maximum ${employerStatementMaxLength} characters`
: undefined
"
@plain-text-length-changed="
(v) => (employerStatementLength = v)
"
></RichTextArea>
</v-col>
</v-row>
<!-- Data Constraints -->
<v-row>
<v-col>
<div class="text-body-1 font-weight-bold">
<label for="dataConstraints"> Data Constraints </label>
<label
for="dataConstraints"
:class="{
'text-error': isSubmit && !isDataConstraintsValid,
}"
>
Data Constraints
</label>
<v-tooltip
id="data-constraints-tooltip"
text="Please share any relevant information, such as limitations, constraints, or dependencies, that may help explain your payroll data. For example, 'Bonus pay is not offered by [employer name]'."
Expand Down Expand Up @@ -430,8 +452,16 @@
<RichTextArea
id="dataConstraints"
v-model="dataConstraints"
placeholder="Maximum 3,000 characters"
:max-length="3000"
:placeholder="`Maximum ${dataConstraintsMaxLength} characters`"
:max-length="dataConstraintsMaxLength"
:error-message="
isSubmit && !isDataConstraintsValid
? `Maximum ${dataConstraintsMaxLength} characters`
: undefined
"
@plain-text-length-changed="
(v) => (dataConstraintsLength = v)
"
></RichTextArea>
</v-col>
</v-row>
Expand Down Expand Up @@ -764,6 +794,10 @@ export default {
approvedRoute: null as string | null,
reportStatus: null,
reportingYearOptions: [] as number[],
employerStatementLength: undefined,
dataConstraintsLength: undefined,
employerStatementMaxLength: 4000,
dataConstraintsMaxLength: 3000,
}),
computed: {
...mapState(useConfigStore, ['config']),
Expand All @@ -786,7 +820,9 @@ export default {
!!this.endMonth &&
!!this.endYear &&
!!this.reportYear &&
!!this.uploadFileValue
!!this.uploadFileValue &&
this.isEmployerStatementValid &&
this.isDataConstraintsValid
);
},
uploadFileSize() {
Expand Down Expand Up @@ -830,6 +866,18 @@ export default {
isEditMode() {
return this.reportId != null;
},
isEmployerStatementValid() {
return (
!this.employerStatementLength ||
this.employerStatementLength <= this.employerStatementMaxLength
);
},
isDataConstraintsValid() {
return (
!this.dataConstraintsLength ||
this.dataConstraintsLength <= this.dataConstraintsMaxLength
);
},
},
watch: {
reportYear: {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/RichTextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const richTextEditor = ref(null);
let quill: Quill | undefined = undefined;
const plainTextLength = ref<number | undefined>(undefined);
const emit = defineEmits(['update:modelValue']);
const emit = defineEmits(['update:modelValue', 'plainTextLengthChanged']);
const props = defineProps<{
placeholder?: string | undefined;
Expand Down Expand Up @@ -92,6 +92,7 @@ onMounted(() => {
const onTextChanged = (delta, oldDelta?, source?) => {
plainTextLength.value = getPlainTextLength();
emit('update:modelValue', getHtml());
emit('plainTextLengthChanged', plainTextLength.value);
};
const setHtml = (html: string | undefined | null) => {
Expand Down

0 comments on commit ed9ddbf

Please sign in to comment.