fix: while adding email check if already exist, allow adding multiple emails at once

This commit is contained in:
Shariq Ansari 2023-12-26 19:55:31 +05:30
parent 7644958ec7
commit 346b12bca5

View File

@ -38,8 +38,8 @@ const props = defineProps({
default: null, default: null,
}, },
errorMessage: { errorMessage: {
type: String, type: Function,
default: 'Invalid value', default: (value) => `${value} is an Invalid value`,
}, },
}) })
@ -49,16 +49,23 @@ const error = ref(null)
const addValue = () => { const addValue = () => {
error.value = null error.value = null
if ( if (currentValue.value) {
currentValue.value && const splitValues = currentValue.value.split(',')
props.validate && splitValues.forEach((value) => {
!props.validate(currentValue.value) value = value.trim()
) { if (value) {
error.value = props.errorMessage // check if value is not already in the values array
if (!values.value.includes(value)) {
// check if value is valid
if (value && props.validate && !props.validate(value)) {
error.value = props.errorMessage(value)
return return
} }
if (currentValue.value) { // add value to values array
values.value.push(currentValue.value) values.value.push(value)
}
}
})
currentValue.value = '' currentValue.value = ''
} }
} }