mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
live inline validation and error output for all fields
This commit is contained in:
parent
40e5144b06
commit
7feb34cc66
@ -1,7 +1,17 @@
|
|||||||
.field {
|
.field {
|
||||||
margin-bottom: var(--spacer);
|
margin-bottom: var(--spacer);
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.field .field {
|
.field .field {
|
||||||
margin-bottom: calc(var(--spacer) / 2);
|
margin-bottom: calc(var(--spacer) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
font-size: var(--font-size-small);
|
||||||
|
color: var(--brand-alert-red);
|
||||||
|
position: absolute;
|
||||||
|
text-align: right;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ import InputElement from './InputElement'
|
|||||||
import Help from './Help'
|
import Help from './Help'
|
||||||
import Label from './Label'
|
import Label from './Label'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
|
import { ErrorMessage } from 'formik'
|
||||||
|
|
||||||
export interface InputProps {
|
export interface InputProps {
|
||||||
name: string
|
name: string
|
||||||
@ -35,15 +36,8 @@ export interface InputProps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Input(props: InputProps): ReactElement {
|
export default function Input(props: Partial<InputProps>): ReactElement {
|
||||||
const {
|
const { required, name, label, help, additionalComponent, field } = props
|
||||||
required,
|
|
||||||
name,
|
|
||||||
label,
|
|
||||||
help,
|
|
||||||
additionalComponent,
|
|
||||||
field
|
|
||||||
} = props as Partial<InputProps>
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.field}>
|
<div className={styles.field}>
|
||||||
@ -52,13 +46,12 @@ export default function Input(props: InputProps): ReactElement {
|
|||||||
</Label>
|
</Label>
|
||||||
<InputElement {...field} {...props} />
|
<InputElement {...field} {...props} />
|
||||||
|
|
||||||
|
<div className={styles.error}>
|
||||||
|
<ErrorMessage name={field.name} />
|
||||||
|
</div>
|
||||||
|
|
||||||
{help && <Help>{help}</Help>}
|
{help && <Help>{help}</Help>}
|
||||||
{additionalComponent && additionalComponent}
|
{additionalComponent && additionalComponent}
|
||||||
|
|
||||||
{/* TODO: Make field errors show up here */}
|
|
||||||
{/* {meta && meta.touched && meta.error ? (
|
|
||||||
<div className="error">{meta.error}</div>
|
|
||||||
) : null} */}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,10 @@ const validationSchema = Yup.object().shape<MetaDataPublishForm>({
|
|||||||
name: Yup.string().required('Required'),
|
name: Yup.string().required('Required'),
|
||||||
author: Yup.string().required('Required'),
|
author: Yup.string().required('Required'),
|
||||||
price: Yup.string().required('Required'),
|
price: Yup.string().required('Required'),
|
||||||
files: Yup.array<File>().required('Required'),
|
files: Yup.array<File>().required('Required').nullable(),
|
||||||
description: Yup.string().required('Required'),
|
description: Yup.string().required('Required'),
|
||||||
license: Yup.string().required('Required'),
|
license: Yup.string().required('Required'),
|
||||||
access: Yup.string().required('Required'),
|
access: Yup.string().min(4).required('Required'),
|
||||||
termsAndConditions: Yup.boolean().required('Required'),
|
termsAndConditions: Yup.boolean().required('Required'),
|
||||||
|
|
||||||
// ---- optional fields ----
|
// ---- optional fields ----
|
||||||
@ -58,9 +58,19 @@ export default function PublishForm({
|
|||||||
async function handleSubmit(values: MetaDataPublishForm) {
|
async function handleSubmit(values: MetaDataPublishForm) {
|
||||||
const submittingToast = toast.info('submitting asset')
|
const submittingToast = toast.info('submitting asset')
|
||||||
|
|
||||||
console.log(values)
|
console.log(`
|
||||||
|
Collected form values:
|
||||||
|
----------------------
|
||||||
|
${values}
|
||||||
|
`)
|
||||||
|
|
||||||
const metadata = transformPublishFormToMetadata(values)
|
const metadata = transformPublishFormToMetadata(values)
|
||||||
console.log(metadata)
|
|
||||||
|
console.log(`
|
||||||
|
Transformed metadata values:
|
||||||
|
----------------------
|
||||||
|
${metadata}
|
||||||
|
`)
|
||||||
|
|
||||||
// if services array stays empty, the default access service
|
// if services array stays empty, the default access service
|
||||||
// will be created by squid-js
|
// will be created by squid-js
|
||||||
|
Loading…
Reference in New Issue
Block a user