Adding forms.
This commit is contained in:
31
better-forms.jsx
Normal file
31
better-forms.jsx
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
const formData = [
|
||||||
|
{ label, defaultValue, validateKeypress, validateBlur, validateSubmit, notifyOnChange },
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
const outFormData = [
|
||||||
|
{ label, defaultValue, ref },
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
function MyForm() {
|
||||||
|
const priceField = makeFormField({ label: "Price", def: 0 })
|
||||||
|
const { fields, submit } = useMemo(makeForm([
|
||||||
|
{ label: 'Cost', min: 0, def: data.cost, required: true, type: CurrencyInput },
|
||||||
|
priceField
|
||||||
|
]), [data])
|
||||||
|
return (
|
||||||
|
<form fields={fields}>
|
||||||
|
<CurrencyInput label="Cost" min={0} def={data.cost} required nofity={[priceField]} />
|
||||||
|
<Field {...fields.cost.field} />
|
||||||
|
<CurrencyInput label="Price" {...priceField} />
|
||||||
|
<button onclick={submit} />
|
||||||
|
</form>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Field({ label, min, def, required, validateKeyPress, validateChange, ref, form, key, depends }) {
|
||||||
|
return (
|
||||||
|
<label value={label}>
|
||||||
|
$<input type="text" onblur={validateChange} ref={ref} />
|
||||||
|
</label>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user