mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
add visibility to required fields when creating a new locality
Co-authored-by: Juhani Kataja <juhani.kataja@helsinki.fi>
This commit is contained in:
co-authored by
Juhani Kataja
parent
41dfa2d70a
commit
d15e2ec6a9
@@ -9,6 +9,7 @@ export const validateLocality = (
|
||||
// const isNew = editData.lid === undefined
|
||||
max_age: {
|
||||
name: 'Age (max)',
|
||||
required: true,
|
||||
asNumber: (num: number) => {
|
||||
if (editData.min_age && num < editData.min_age) return 'Max value cannot be lower than min'
|
||||
return
|
||||
@@ -16,6 +17,7 @@ export const validateLocality = (
|
||||
},
|
||||
min_age: {
|
||||
name: 'Age (min)',
|
||||
required: true,
|
||||
asNumber: (num: number) => {
|
||||
if (editData.max_age && num > editData.max_age) return 'Min value cannot be higher than max'
|
||||
return
|
||||
@@ -23,6 +25,11 @@ export const validateLocality = (
|
||||
},
|
||||
loc_name: {
|
||||
name: 'Locality name',
|
||||
required: true,
|
||||
},
|
||||
country: {
|
||||
name: 'Country',
|
||||
required: true,
|
||||
},
|
||||
date_meth: {
|
||||
name: 'Dating method',
|
||||
|
||||
@@ -13,7 +13,7 @@ export type Validators<T> = { [field in keyof T]: Validator }
|
||||
|
||||
const validate: (validator: Validator, value: unknown) => ValidationError = (validator: Validator, value: unknown) => {
|
||||
const { required, minLength, maxLength, asNumber, asString } = validator
|
||||
if (value === null || value === undefined) return required ? 'This field is required' : null
|
||||
if (value === null || value === undefined || value === '') return required ? 'This field is required' : null
|
||||
if (asNumber) {
|
||||
if (typeof value !== 'number') return 'Value must be a valid number' // If this happens, code is broken somewhere
|
||||
if (typeof asNumber === 'function') return asNumber(value)
|
||||
|
||||
Reference in New Issue
Block a user