Skip to content

Commit 3290d1e

Browse files
sddiouldeSaliou Diallo
andauthored
[PAY-3258] BoxedTextField can error before form submission (#9305)
Co-authored-by: Saliou Diallo <[email protected]>
1 parent 1dd131f commit 3290d1e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

packages/mobile/src/components/edit/PriceAndAudienceField/PremiumRadioField/BoxedTextField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const BoxedTextField = (props: BoxedTextFieldProps) => {
5252
<TextField
5353
style={styles.textField}
5454
styles={{ root: styles.textInput }}
55+
errorBeforeSubmit
5556
{...other}
5657
/>
5758
</View>

packages/mobile/src/components/edit/PriceAndAudienceField/PriceAndAudienceScreen.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export const PriceAndAudienceScreen = () => {
4242
useField<boolean>('is_stream_gated')
4343
const [{ value: streamConditions }, , { setValue: setStreamConditions }] =
4444
useField<Nullable<AccessConditions>>('stream_conditions')
45+
const [, , { setValue: setPreviewValue }] = useField<Nullable<number>>(
46+
'preview_start_seconds'
47+
)
4548
const [{ value: isScheduledRelease }] = useField<boolean>(
4649
'is_scheduled_release'
4750
)
@@ -204,6 +207,7 @@ export const PriceAndAudienceScreen = () => {
204207
onValueChange={() => {
205208
setIsStreamGated(false)
206209
setStreamConditions(null)
210+
setPreviewValue(null)
207211
}}
208212
/>
209213
<PremiumRadioField

packages/mobile/src/components/fields/TextField.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type TextFieldProps = FieldProps &
1414
TextInputProps & {
1515
noGutter?: boolean
1616
debouncedValidationMs?: number
17+
errorBeforeSubmit?: boolean
1718
}
1819

1920
const useStyles = makeStyles(({ spacing, typography }) => ({
@@ -46,6 +47,7 @@ export const TextField = (props: TextFieldProps) => {
4647
id,
4748
onChangeText,
4849
error: errorProp,
50+
errorBeforeSubmit,
4951
debouncedValidationMs = 0,
5052
...other
5153
} = props
@@ -72,7 +74,10 @@ export const TextField = (props: TextFieldProps) => {
7274
}, [debouncedValidationMs, debouncedValidateField, name, value])
7375
const label = required ? `${labelProp} *` : labelProp
7476

75-
const hasError = (errorProp ?? errorMessage) && touched && submitCount > 0
77+
const hasError =
78+
(errorProp ?? errorMessage) &&
79+
touched &&
80+
(errorBeforeSubmit || submitCount > 0)
7681

7782
const handleChangeText = useCallback(
7883
(text: string) => {

0 commit comments

Comments
 (0)