mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
added dynamic validation to edit form
This commit is contained in:
parent
236649c910
commit
35d3a548b6
@ -1,11 +1,36 @@
|
|||||||
import { FileInfo } from '@oceanprotocol/lib'
|
import { FileInfo } from '@oceanprotocol/lib'
|
||||||
|
import { validateFieldSchaclSchema } from '@utils/schaclSchema'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
export const validationSchema = Yup.object().shape({
|
export const validationSchema = Yup.object().shape({
|
||||||
name: Yup.string()
|
name: Yup.string()
|
||||||
.min(4, (param) => `Title must be at least ${param.min} characters`)
|
.required('Required')
|
||||||
.required('Required'),
|
.test(async (value, { path, createError }): Promise<any> => {
|
||||||
description: Yup.string().required('Required').min(10),
|
if (!value) return
|
||||||
|
const keyField = path.split('.')[0]
|
||||||
|
const valueField = path.split('.')[1]
|
||||||
|
|
||||||
|
return await validateFieldSchaclSchema(
|
||||||
|
keyField,
|
||||||
|
valueField,
|
||||||
|
value,
|
||||||
|
createError
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
description: Yup.string()
|
||||||
|
.required('Required')
|
||||||
|
.test(async (value, { path, createError }): Promise<any> => {
|
||||||
|
if (!value) return
|
||||||
|
const keyField = path.split('.')[0]
|
||||||
|
const valueField = path.split('.')[1]
|
||||||
|
|
||||||
|
return await validateFieldSchaclSchema(
|
||||||
|
keyField,
|
||||||
|
valueField,
|
||||||
|
value,
|
||||||
|
createError
|
||||||
|
)
|
||||||
|
}),
|
||||||
price: Yup.number().required('Required'),
|
price: Yup.number().required('Required'),
|
||||||
files: Yup.array<FileInfo[]>()
|
files: Yup.array<FileInfo[]>()
|
||||||
.of(
|
.of(
|
||||||
@ -24,7 +49,20 @@ export const validationSchema = Yup.object().shape({
|
|||||||
)
|
)
|
||||||
.nullable(),
|
.nullable(),
|
||||||
timeout: Yup.string().required('Required'),
|
timeout: Yup.string().required('Required'),
|
||||||
author: Yup.string().nullable()
|
author: Yup.string()
|
||||||
|
.required('Required')
|
||||||
|
.test(async (value, { path, createError }): Promise<any> => {
|
||||||
|
if (!value) return
|
||||||
|
const keyField = path.split('.')[0]
|
||||||
|
const valueField = path.split('.')[1]
|
||||||
|
|
||||||
|
return await validateFieldSchaclSchema(
|
||||||
|
keyField,
|
||||||
|
valueField,
|
||||||
|
value,
|
||||||
|
createError
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
export const computeSettingsValidationSchema = Yup.object().shape({
|
export const computeSettingsValidationSchema = Yup.object().shape({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user