validation on Select field (#8316)
fix #8204 I changed "API keys" to "API values". Stopped inputting special characters in Select field option keys. @lucasbordeau please check the changes and tell me if I need to do any other changes. :) --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@ -2,7 +2,7 @@ import { errors } from '@/settings/data-model/fields/forms/utils/errorMessages';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { METADATA_LABEL_VALID_PATTERN } from '~/pages/settings/data-model/constants/MetadataLabelValidPattern';
|
||||
import { computeMetadataNameFromLabelOrThrow } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';
|
||||
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';
|
||||
export const metadataLabelSchema = (existingLabels?: string[]) => {
|
||||
return z
|
||||
.string()
|
||||
@ -12,7 +12,7 @@ export const metadataLabelSchema = (existingLabels?: string[]) => {
|
||||
.refine(
|
||||
(label) => {
|
||||
try {
|
||||
computeMetadataNameFromLabelOrThrow(label);
|
||||
computeMetadataNameFromLabel(label);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
@ -28,9 +28,7 @@ export const metadataLabelSchema = (existingLabels?: string[]) => {
|
||||
if (!existingLabels || !label?.length) {
|
||||
return true;
|
||||
}
|
||||
return !existingLabels.includes(
|
||||
computeMetadataNameFromLabelOrThrow(label),
|
||||
);
|
||||
return !existingLabels.includes(computeMetadataNameFromLabel(label));
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import { themeColorSchema } from 'twenty-ui';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { FieldMetadataItemOption } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { computeOptionValueFromLabelOrThrow } from '~/pages/settings/data-model/utils/compute-option-value-from-label.utils';
|
||||
import { computeOptionValueFromLabel } from '~/pages/settings/data-model/utils/compute-option-value-from-label.utils';
|
||||
|
||||
const selectOptionSchema = z
|
||||
.object({
|
||||
@ -15,7 +15,7 @@ const selectOptionSchema = z
|
||||
.refine(
|
||||
(option) => {
|
||||
try {
|
||||
computeOptionValueFromLabelOrThrow(option.label);
|
||||
computeOptionValueFromLabel(option.label);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user