on master help sign in
fix: final-form-set-field-data was causing a validation loop...
20e3963Matt Condon (shrugs)
src/form/BridgeForm.js+1−8
@@ -1,12 +1,10 @@
1import React, { useCallback } from 'react';
1import React, { useCallback } from 'react';
2import { Form } from 'react-final-form';
2import { Form } from 'react-final-form';
3−import setFieldData from 'final-form-set-field-data';
4import arrayMutators from 'final-form-arrays';
3import arrayMutators from 'final-form-arrays';
5import { noop } from 'lodash';
4import { noop } from 'lodash';
6
5
7import ValuesHandler from './ValuesHandler';
6import ValuesHandler from './ValuesHandler';
8import ValidationPauser from './ValidationPauser';
7import ValidationPauser from './ValidationPauser';
9−import WarningEngine from './WarningEngine';
10
8
11/**
9/**
12 * BridgeForm adds nice-to-haves for every form in bridge.
10 * BridgeForm adds nice-to-haves for every form in bridge.
@@ -21,7 +19,6 @@ export default function BridgeForm({
21 onValues,
19 onValues,
22 onSubmit = noop,
20 onSubmit = noop,
23 afterSubmit = noop,
21 afterSubmit = noop,
24− warnings,
25 ...rest
22 ...rest
26}) {
23}) {
27 const _onSubmit = useCallback(
24 const _onSubmit = useCallback(
@@ -37,13 +34,9 @@ export default function BridgeForm({
37 );
34 );
38
35
39 return (
36 return (
40− <Form
41− mutators={{ setFieldData, ...arrayMutators }}
37+ <Form mutators={{ ...arrayMutators }} onSubmit={_onSubmit} {...rest}>
42− onSubmit={_onSubmit}
43− {...rest}>
44 {formProps => (
38 {formProps => (
45 <>
39 <>
46− {warnings && <WarningEngine warnings={warnings} />}
47 <ValidationPauser />
40 <ValidationPauser />
48 {children(formProps)}
41 {children(formProps)}
49 {onValues && <ValuesHandler onValues={onValues} />}
42 {onValues && <ValuesHandler onValues={onValues} />}
src/form/WarningEngine.jsdeleted−15
@@ -1,15 +0,0 @@
1−import { useEffect } from 'react';
2−import { useForm } from 'react-final-form';
3−import { map } from 'lodash';
4−
5−export default function WarningEngine({ warnings }) {
6− const form = useForm();
7−
8− useEffect(() => {
9− map(warnings, (warning, name) =>
10− form.mutators.setFieldData(name, { warning })
11− );
12− }, [form, warnings]);
13−
14− return null;
15−}
src/indigo-react/components/Input.js+2−8
@@ -14,6 +14,7 @@ export default function Input({
14 accessory,
14 accessory,
15 disabled = false,
15 disabled = false,
16 mono = false,
16 mono = false,
17+ warning,
17
18
18 // callbacks
19 // callbacks
19 onEnter,
20 onEnter,
@@ -26,14 +27,7 @@ export default function Input({
26}) {
27}) {
27 const {
28 const {
28 input,
29 input,
29− meta: {
30− active,
31− error,
32− submitting,
30+ meta: { active, error, submitting, touched, valid },
33− touched,
34− valid,
35− data: { warning },
36− },
37 } = useField(name, config);
31 } = useField(name, config);
38
32
39 disabled = disabled || submitting;
33 disabled = disabled || submitting;
src/indigo-react/components/SelectInput.js+2−8
@@ -16,17 +16,11 @@ export default function SelectInput({
16 mono = false,
16 mono = false,
17 options = [],
17 options = [],
18 disabled = false,
18 disabled = false,
19+ warning,
19}) {
20}) {
20 const {
21 const {
21 input,
22 input,
22− meta: {
23− active,
24− error,
25− submitting,
23+ meta: { active, error, submitting, touched, valid },
26− touched,
27− valid,
28− data: { warning },
29− },
30 } = useField(name, {
24 } = useField(name, {
31 type: 'select',
25 type: 'select',
32 });
26 });
src/views/Login/Ticket.js+6−2
@@ -151,14 +151,18 @@ export default function Ticket({ className, goHome }) {
151 return (
151 return (
152 <Grid className={cn('mt4', className)}>
152 <Grid className={cn('mt4', className)}>
153 <BridgeForm
153 <BridgeForm
154− warnings={warnings}
155 validate={validate}
154 validate={validate}
156 onValues={onValues}
155 onValues={onValues}
157 afterSubmit={goHome}
156 afterSubmit={goHome}
158 initialValues={initialValues}>
157 initialValues={initialValues}>
159 {({ handleSubmit }) => (
158 {({ handleSubmit }) => (
160 <>
159 <>
160+ <Grid.Item
161+ full
161− <Grid.Item full as={PointInput} name="point" />
162+ as={PointInput}
163+ name="point"
164+ warning={warnings.point}
165+ />
162
166
163 <Condition when="useShards" is={false}>
167 <Condition when="useShards" is={false}>
164 <Grid.Item
168 <Grid.Item