Skip to content

Commit

Permalink
BoxedTextField can error before form submission. Also fix free selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Saliou Diallo committed Jul 30, 2024
1 parent 28b71e0 commit 259164e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const BoxedTextField = (props: BoxedTextFieldProps) => {
<TextField
style={styles.textField}
styles={{ root: styles.textInput }}
errorBeforeSubmit
{...other}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export const PriceAndAudienceScreen = () => {
useField<boolean>('is_stream_gated')
const [{ value: streamConditions }, , { setValue: setStreamConditions }] =
useField<Nullable<AccessConditions>>('stream_conditions')
const [, , { setValue: setPreviewValue }] = useField<Nullable<number>>(
'preview_start_seconds'
)
const [{ value: isScheduledRelease }] = useField<boolean>(
'is_scheduled_release'
)
Expand Down Expand Up @@ -204,6 +207,7 @@ export const PriceAndAudienceScreen = () => {
onValueChange={() => {
setIsStreamGated(false)
setStreamConditions(null)
setPreviewValue(null)
}}
/>
<PremiumRadioField
Expand Down
7 changes: 6 additions & 1 deletion packages/mobile/src/components/fields/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type TextFieldProps = FieldProps &
TextInputProps & {
noGutter?: boolean
debouncedValidationMs?: number
errorBeforeSubmit?: boolean
}

const useStyles = makeStyles(({ spacing, typography }) => ({
Expand Down Expand Up @@ -46,6 +47,7 @@ export const TextField = (props: TextFieldProps) => {
id,
onChangeText,
error: errorProp,
errorBeforeSubmit,
debouncedValidationMs = 0,
...other
} = props
Expand All @@ -72,7 +74,10 @@ export const TextField = (props: TextFieldProps) => {
}, [debouncedValidationMs, debouncedValidateField, name, value])
const label = required ? `${labelProp} *` : labelProp

const hasError = (errorProp ?? errorMessage) && touched && submitCount > 0
const hasError =
(errorProp ?? errorMessage) &&
touched &&
(errorBeforeSubmit || submitCount > 0)

const handleChangeText = useCallback(
(text: string) => {
Expand Down

0 comments on commit 259164e

Please sign in to comment.