feat(frontend): add reusable search select and wire it into machine creation

fix(frontend): guard custom field persistence against non-string values
This commit is contained in:
Matthieu
2025-10-13 17:03:06 +02:00
parent 469bcb82d1
commit e297d1bb39
8 changed files with 544 additions and 73 deletions

View File

@@ -597,7 +597,7 @@ const requiredCustomFieldsFilled = computed(() =>
if (field.type === 'boolean') {
return field.value === 'true' || field.value === 'false'
}
return field.value !== ''
return toFieldString(field.value).trim() !== ''
}),
)
@@ -609,6 +609,19 @@ const canSubmit = computed(() => Boolean(
!submitting.value,
))
const toFieldString = (value: unknown): string => {
if (value === null || value === undefined) {
return ''
}
if (typeof value === 'string') {
return value
}
if (typeof value === 'number' || typeof value === 'boolean') {
return String(value)
}
return ''
}
const getStructureCustomFields = (structure: ComponentModelStructure | null) => {
return Array.isArray(structure?.customFields) ? structure.customFields : []
}
@@ -917,13 +930,13 @@ const shouldPersistField = (field: CustomFieldInput) => {
if (field.type === 'boolean') {
return field.value === 'true' || field.value === 'false'
}
return field.value.trim() !== ''
return toFieldString(field.value).trim() !== ''
}
const formatValueForPersistence = (field: CustomFieldInput) => {
if (field.type === 'boolean') {
return field.value === 'true' ? 'true' : 'false'
}
return field.value.trim()
return toFieldString(field.value).trim()
}
</script>