Skip to content

Commit a84b407

Browse files
committed
Ignore string prop values that don't match string type
1 parent 042904c commit a84b407

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/connect-react/src/hooks/form-context.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ export const FormContextProvider = <T extends ConfigurableProps>({
173173
const propErrors = (prop: ConfigurableProp, value: unknown): string[] => {
174174
const errs: string[] = [];
175175
if (prop.optional || prop.hidden || prop.disabled) return []
176-
if (typeof value === "undefined") {
177-
return [
178-
"required",
179-
]
180-
}
181176
if (prop.type === "app") {
182177
const field = fields[prop.name]
183178
if (field) {

packages/connect-react/src/utils/component.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ export type ValidationOpts<T extends ConfigurableProp> = {
5050

5151
export function arrayPropErrors(opts: ValidationOpts<ConfigurablePropStringArray>): string[] | undefined {
5252
const _values = valuesFromOptions(opts.value)
53-
if (typeof _values === "undefined") {
53+
if (!opts.prop.default && typeof _values === "undefined") {
5454
return [
5555
"required",
5656
]
5757
}
58-
if (Array.isArray(_values) && !_values.length) return [
58+
if (!opts.prop.default && Array.isArray(_values) && !_values.length) return [
5959
"empty array",
6060
]
6161
}
@@ -73,7 +73,7 @@ export function integerPropErrors(opts: ValidationOpts<ConfigurablePropInteger>)
7373
} = opts
7474
const value = valueFromOption(valueOpt)
7575

76-
if (value == null || typeof value === "undefined") return [
76+
if (!prop.default && value == null || typeof value === "undefined") return [
7777
"required",
7878
]
7979

@@ -92,9 +92,15 @@ export function integerPropErrors(opts: ValidationOpts<ConfigurablePropInteger>)
9292

9393
export function stringPropErrors(opts: ValidationOpts<ConfigurablePropString>): string[] | undefined {
9494
const _value = valueFromOption(opts.value)
95-
if (!_value) return [
96-
"string must not be empty",
97-
]
95+
96+
if (!opts.prop.default) {
97+
if (typeof _value === "undefined" || _value == null) return [
98+
"required",
99+
]
100+
if (!String(_value).length) return [
101+
"string must not be empty",
102+
]
103+
}
98104
}
99105

100106
type AppWithExtractedCustomFields = App & {

0 commit comments

Comments
 (0)