-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display initial form fields with validation
- Loading branch information
1 parent
7fd235e
commit 031a53f
Showing
12 changed files
with
312 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script setup lang="ts"> | ||
import { toRef } from 'vue'; | ||
import { useField, ErrorMessage } from 'vee-validate'; | ||
import { Dropdown } from '@/lib/primevue'; | ||
// Props | ||
type Props = { | ||
helpText?: string; | ||
label?: string; | ||
name: string; | ||
placeholder?: string; | ||
disabled?: boolean; | ||
options: Array<string>; | ||
}; | ||
const props = withDefaults(defineProps<Props>(), { | ||
helpText: '', | ||
type: 'text', | ||
label: '', | ||
placeholder: '', | ||
disabled: false | ||
}); | ||
const { errorMessage, value } = useField<string>(toRef(props, 'name')); | ||
</script> | ||
|
||
<template> | ||
<div class="field col-12"> | ||
<label :for="name">{{ label }}</label> | ||
<Dropdown | ||
v-model.trim="value" | ||
:aria-describedby="`${name}-help`" | ||
:name="name" | ||
:placeholder="placeholder" | ||
:class="'w-full ' + { 'p-invalid': errorMessage }" | ||
:disabled="disabled" | ||
:options="props.options" | ||
/> | ||
<small :id="`${name}-help`">{{ helpText }}</small> | ||
<ErrorMessage :name="name" /> | ||
</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,42 @@ | ||
<script setup lang="ts"> | ||
import { toRef } from 'vue'; | ||
import { useField, ErrorMessage } from 'vee-validate'; | ||
import { Textarea } from '@/lib/primevue'; | ||
// Props | ||
type Props = { | ||
helpText?: string; | ||
label?: string; | ||
name: string; | ||
placeholder?: string; | ||
disabled?: boolean; | ||
}; | ||
const props = withDefaults(defineProps<Props>(), { | ||
helpText: '', | ||
type: 'text', | ||
label: '', | ||
placeholder: '', | ||
disabled: false | ||
}); | ||
const { errorMessage, value } = useField<string>(toRef(props, 'name')); | ||
</script> | ||
|
||
<template> | ||
<div class="field col-12"> | ||
<label :for="name">{{ label }}</label> | ||
<Textarea | ||
v-model.trim="value" | ||
:aria-describedby="`${name}-help`" | ||
:name="name" | ||
:placeholder="placeholder" | ||
:class="'w-full ' + { 'p-invalid': errorMessage }" | ||
:disabled="disabled" | ||
:rows="5" | ||
/> | ||
<small :id="`${name}-help`">{{ helpText }}</small> | ||
<ErrorMessage :name="name" /> | ||
</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
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export { default as CopyToClipboard } from './CopyToClipboard.vue'; | ||
export { default as Dropdown } from './Dropdown.vue'; | ||
export { default as GridRow } from './GridRow.vue'; | ||
export { default as Password } from './Password.vue'; | ||
export { default as TextArea } from './TextArea.vue'; | ||
export { default as TextInput } from './TextInput.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,152 @@ | ||
<script setup lang="ts"> | ||
import { Form } from 'vee-validate'; | ||
import { number, object, string } from 'yup'; | ||
import { Dropdown, TextArea, TextInput } from '@/components/form'; | ||
import { Button } from '@/lib/primevue'; | ||
// Props | ||
type Props = { | ||
editable: boolean; | ||
submission: any; | ||
submissionStatus: any; | ||
}; | ||
const props = withDefaults(defineProps<Props>(), {}); | ||
// Emites | ||
const emit = defineEmits(['submit', 'cancel']); | ||
// Default form values | ||
const initialFormValues: any = { | ||
assignee: props.submissionStatus.user?.username, | ||
confirmationId: props.submission.confirmationId, | ||
intakeStatus: props.submissionStatus.code, | ||
queuePriority: props.submission.submission.data.queuePriority | ||
}; | ||
// Form validation schema | ||
const formSchema = object({ | ||
addedToATS: string().oneOf(['Y', 'N']).required().label('Added to ATS'), | ||
applicationStatus: string() | ||
.matches(/^[a-zA-Z]+$/, { excludeEmptyString: true, message: 'Application Status may only contain letters' }) | ||
.label('Application Status'), | ||
assignee: string() | ||
.when('intakeStatus', { | ||
is: (val: string) => val !== 'SUBMITTED', | ||
then: (schema) => schema.required(), | ||
otherwise: (schema) => schema.notRequired() | ||
}) | ||
.label('Assignee'), | ||
atsClientNumber: string() | ||
.when('addedToATS', { | ||
is: 'Y', | ||
then: (schema) => schema.required(), | ||
otherwise: (schema) => schema.notRequired() | ||
}) | ||
.label('ATS Client Number'), | ||
confirmationId: string().required().label('Confirmation ID'), | ||
financiallySupported: string().oneOf(['Y', 'N']).required().label('Financially Supported'), | ||
intakeStatus: string().required().label('Intake Status'), | ||
queuePriority: number() | ||
.required() | ||
.min(0) | ||
.integer() | ||
.typeError('Queue Priority must be a number') | ||
.label('Queue Priority') | ||
}); | ||
const intakeStatusList = ['SUBMITTED', 'ASSIGNED', 'COMPLETED']; | ||
// Actions | ||
const onCancel = () => { | ||
emit('cancel'); | ||
}; | ||
const onSubmit = (values: any) => { | ||
console.log(values); // eslint-disable-line no-console | ||
emit('submit'); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="formgrid grid"> | ||
<Form | ||
v-slot="{ handleReset }" | ||
:initial-values="initialFormValues" | ||
:validation-schema="formSchema" | ||
@submit="onSubmit" | ||
> | ||
<TextInput | ||
name="confirmationId" | ||
label="Confirmation ID *" | ||
:disabled="!props.editable" | ||
autofocus | ||
/> | ||
<TextInput | ||
name="atsClientNumber" | ||
label="ATS Client Number" | ||
:disabled="!props.editable" | ||
/> | ||
<TextInput | ||
name="addedToATS" | ||
label="Added to ATS *" | ||
:disabled="!props.editable" | ||
/> | ||
<TextInput | ||
name="financiallySupported" | ||
label="Financially Supported *" | ||
:disabled="!props.editable" | ||
/> | ||
<TextInput | ||
name="applicationStatus" | ||
label="Application Status" | ||
:disabled="!props.editable" | ||
/> | ||
<TextInput | ||
name="queuePriority" | ||
label="Queue Priority" | ||
:disabled="!props.editable" | ||
/> | ||
<TextArea | ||
name="notes" | ||
label="Notes" | ||
:disabled="!props.editable" | ||
/> | ||
<TextInput | ||
name="assignee" | ||
label="Assignee" | ||
:disabled="!props.editable" | ||
/> | ||
<Dropdown | ||
name="intakeStatus" | ||
label="Intake Status *" | ||
:disabled="!props.editable" | ||
:options="intakeStatusList" | ||
/> | ||
|
||
<div class="field col-12"> | ||
<Button | ||
label="Save" | ||
type="submit" | ||
icon="pi pi-check" | ||
:disabled="!props.editable" | ||
/> | ||
|
||
<Button | ||
label="Cancel" | ||
outlined | ||
class="ml-2" | ||
icon="pi pi-times" | ||
:disabled="!props.editable" | ||
@click=" | ||
() => { | ||
handleReset(); | ||
onCancel(); | ||
} | ||
" | ||
/> | ||
</div> | ||
</Form> | ||
</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
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
Oops, something went wrong.