Skip to content

Commit d78e8d5

Browse files
committed
show single error on validation; remove expiration from email page
1 parent 1bd8a62 commit d78e8d5

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

components/form.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function FormGroup ({ className, label, children }) {
486486

487487
function InputInner ({
488488
prepend, append, hint, warn, showValid, onChange, onBlur, overrideValue, appendValue,
489-
innerRef, noForm, clear, onKeyDown, inputGroupClassName, debounce: debounceTime, maxLength,
489+
innerRef, noForm, clear, onKeyDown, inputGroupClassName, debounce: debounceTime, maxLength, hideError,
490490
...props
491491
}) {
492492
const [field, meta, helpers] = noForm ? [{}, {}, {}] : useField(props)
@@ -574,7 +574,7 @@ function InputInner ({
574574
onKeyDown={onKeyDownInner}
575575
onChange={onChangeInner}
576576
onBlur={onBlurInner}
577-
isInvalid={invalid}
577+
isInvalid={!hideError && invalid}
578578
isValid={showValid && meta.initialValue !== meta.value && meta.touched && !meta.error}
579579
/>
580580
{(isClient && clear && field.value && !props.readOnly) &&
@@ -1248,7 +1248,7 @@ export function MultiInput ({
12481248
}) {
12491249
const [inputs, setInputs] = useState(new Array(length).fill(''))
12501250
const inputRefs = useRef(new Array(length).fill(null))
1251-
const [, , helpers] = useField({ name })
1251+
const [, meta, helpers] = useField({ name })
12521252

12531253
useEffect(() => {
12541254
autoFocus && inputRefs.current[0].focus()
@@ -1307,21 +1307,29 @@ export function MultiInput ({
13071307
}, [inputs, length, updateInputs])
13081308

13091309
return (
1310-
<FormGroup label={label} className={groupClassName}>
1311-
{inputs.map((value, index) => (
1312-
<InputInner
1313-
name={name} // todo: use this for single input validation
1314-
key={index}
1315-
type={inputType}
1316-
value={value}
1317-
innerRef={(el) => { inputRefs.current[index] = el }}
1318-
onChange={(formik, e) => handleChange(formik, e, index)}
1319-
onKeyDown={e => handleKeyDown(e, index)}
1320-
style={{ textAlign: 'center' }}
1321-
prepend={showSequence && <InputGroup.Text>{index}</InputGroup.Text>}
1322-
{...props}
1323-
/>
1324-
))}
1310+
<FormGroup label={label}>
1311+
<div className={groupClassName}>
1312+
{inputs.map((value, index) => (
1313+
<InputInner
1314+
name={name}
1315+
key={index}
1316+
type={inputType}
1317+
value={value}
1318+
innerRef={(el) => { inputRefs.current[index] = el }}
1319+
onChange={(formik, e) => handleChange(formik, e, index)}
1320+
onKeyDown={e => handleKeyDown(e, index)}
1321+
style={{ textAlign: 'center' }}
1322+
prepend={showSequence && <InputGroup.Text>{index}</InputGroup.Text>}
1323+
hideError
1324+
{...props}
1325+
/>
1326+
))}
1327+
</div>
1328+
{meta.touched && meta.error && (
1329+
<BootstrapForm.Control.Feedback type='invalid' className='d-block'>
1330+
{meta.error}
1331+
</BootstrapForm.Control.Feedback>
1332+
)}
13251333
</FormGroup>
13261334
)
13271335
}

pages/email.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function Email () {
3131
<Image className='rounded-1 shadow-sm' width='640' height='302' src={`${process.env.NEXT_PUBLIC_ASSET_PREFIX}/cowboy-saloon.gif`} fluid />
3232
</video>
3333
<h2 className='pt-4'>Check your email</h2>
34-
<h4 className='text-muted pt-2 pb-4'>a 5-minutes magic code has been sent to {callback ? callback.email : 'your email address'}</h4>
34+
<h4 className='text-muted pt-2 pb-4'>a magic code has been sent to {callback ? callback.email : 'your email address'}</h4>
3535
<MagicCodeForm onSubmit={(token) => pushCallback(token)} />
3636
</div>
3737
</StaticLayout>

0 commit comments

Comments
 (0)