Regex Expressions as Actions #964
Answered
by
posva
Shiinoya
asked this question in
Help and Questions
-
Hello guys, I'm pretty new with programming and was wondering if I could do the below and if so, how? I am using Vue 3, Composition API, TS, Pinia 2.0.0 I have a Patient Component with a form that needs values to be validated. I wanted to validate what the user types in and return a boolean ( to trigger an error if invalid ). How can I use these actions inside my component and how can I pass data into them? Any help or suggestions would be appreciated. import { defineStore } from 'pinia';
import { useStorage } from '@vueuse/core';
export const usePatientValidationStore = defineStore('patient-validation', {
state: () => {
return {
validation: useStorage('patient-validation', {
// True = valid entry
firstName: true,
lastName: true,
dob: { day: true, month: true, year: true },
patientId: true
}),
actions: {
async validateFLName() {
/^[a-zA-Z]+$/.test;
},
async validateDobDay() {
/^(([0]?[1-9])|([1-2][0-9])|(3[01]))$/.test;
},
async validateDobMonth() {
/^(0?[1-9]|1[012])$/.test;
},
async validateDobYear() {
/^(19|20)\d{2}$/.test;
}
}
};
}
}); |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Jan 20, 2022
Replies: 1 comment
-
You need to move the actions outside of the state: export const usePatientValidationStore = defineStore('patient-validation', {
state: () => {
return {
validation: useStorage('patient-validation', {
// True = valid entry
firstName: true,
lastName: true,
dob: { day: true, month: true, year: true },
patientId: true,
}),
}
},
actions: {
async validateFLName() {
;/^[a-zA-Z]+$/.test
},
async validateDobDay() {
;/^(([0]?[1-9])|([1-2][0-9])|(3[01]))$/.test
},
async validateDobMonth() {
;/^(0?[1-9]|1[012])$/.test
},
async validateDobYear() {
;/^(19|20)\d{2}$/.test
},
},
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Shiinoya
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to move the actions outside of the state: