Skip to content

Commit 2187614

Browse files
committedJul 18, 2022
Changed the Validation Check
1 parent 59f258a commit 2187614

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed
 

‎packages/spectrum/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/spectrum/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "test-jsonforms-react-spectrum-renderers",
3-
"version": "0.0.87",
3+
"version": "0.0.93",
44
"description": "React Spectrum Renderer Set for JSONForms",
55
"repository": "https://github.com/headwirecom/jsonforms-react-spectrum-renderers",
66
"bugs": "https://github.com/headwirecom/jsonforms-react-spectrum-renderers/issues",

‎packages/spectrum/src/spectrum-control/InputText.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,30 @@ export const InputText = React.memo(
5858
? undefined
5959
: '100%';
6060

61-
const isValidCheck = () => {
61+
const [inputText, onChange] = useDebouncedChange(
62+
handleChange,
63+
schema?.default ?? '',
64+
data,
65+
path
66+
);
67+
68+
const isValidCheck = React.useMemo(() => {
6269
let minLength = appliedUiSchemaOptions.minLength ?? (required ? 1 : 0);
6370
let maxLength = appliedUiSchemaOptions.maxLength ?? Infinity;
64-
if (isValid && !data && minLength === 0) {
65-
return 'valid';
66-
} else if (!data) {
67-
return 'invalid';
71+
if (isValid && !inputText && minLength === 0) {
72+
return true;
73+
} else if (!inputText) {
74+
return false;
6875
} else if (
6976
isValid &&
70-
data.length >= minLength &&
71-
data.length <= maxLength
77+
inputText.length >= minLength &&
78+
inputText.length <= maxLength
7279
) {
73-
return 'valid';
80+
return true;
7481
} else {
75-
return 'invalid';
82+
return false;
7683
}
77-
};
84+
}, [inputText]);
7885

7986
const errorMessage = () => {
8087
let minLength = appliedUiSchemaOptions.minLength ?? (required ? 1 : null);
@@ -107,20 +114,13 @@ export const InputText = React.memo(
107114
}
108115
}, [appliedUiSchemaOptions.NonFocusPlaceholder]); */
109116

110-
const clearNonFocusPlaceholder = () => {
117+
/* const clearNonFocusPlaceholder = () => {
111118
if (data === appliedUiSchemaOptions.NonFocusPlaceholder) {
112119
handleChange(path, '');
113120
} else if (!data && !schema?.default) {
114121
handleChange(path, appliedUiSchemaOptions.NonFocusPlaceholder);
115122
}
116-
};
117-
118-
const [inputText, onChange] = useDebouncedChange(
119-
handleChange,
120-
schema?.default ?? '',
121-
data,
122-
path
123-
);
123+
}; */
124124

125125
const fileBrowser = uischema.options?.fileBrowser;
126126
const fileBrowserOptions =
@@ -170,9 +170,9 @@ export const InputText = React.memo(
170170
appliedUiSchemaOptions.necessityIndicator ?? null
171171
}
172172
onChange={onChange}
173-
onFocusChange={clearNonFocusPlaceholder}
173+
//onFocusChange={clearNonFocusPlaceholder}
174174
type={appliedUiSchemaOptions.format ?? 'text'}
175-
validationState={isValidCheck()}
175+
validationState={isValidCheck ? 'valid' : 'invalid'}
176176
value={inputText}
177177
/>
178178
{fileBrowserOptions && (

‎packages/spectrum/src/spectrum-control/InputTextArea.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,30 @@ export const InputTextArea = React.memo(
5151
? undefined
5252
: '100%';
5353

54-
const isValidCheck = () => {
54+
const [inputText, onChange] = useDebouncedChange(
55+
handleChange,
56+
schema?.default ?? '',
57+
data,
58+
path
59+
);
60+
61+
const isValidCheck = React.useMemo(() => {
5562
let minLength = appliedUiSchemaOptions.minLength ?? (required ? 1 : 0);
5663
let maxLength = appliedUiSchemaOptions.maxLength ?? Infinity;
57-
if (isValid && !data && minLength === 0) {
58-
return 'valid';
59-
} else if (!data) {
60-
return 'invalid';
64+
if (isValid && !inputText && minLength === 0) {
65+
return true;
66+
} else if (!inputText) {
67+
return false;
6168
} else if (
6269
isValid &&
63-
data.length >= minLength &&
64-
data.length <= maxLength
70+
inputText.length >= minLength &&
71+
inputText.length <= maxLength
6572
) {
66-
return 'valid';
73+
return true;
6774
} else {
68-
return 'invalid';
75+
return false;
6976
}
70-
};
77+
}, [inputText]);
7178

7279
const errorMessage = () => {
7380
let minLength = appliedUiSchemaOptions.minLength ?? (required ? 1 : null);
@@ -87,30 +94,23 @@ export const InputTextArea = React.memo(
8794
}
8895
}, [!data, schema?.default]);
8996

90-
useEffect(() => {
97+
/* useEffect(() => {
9198
if (
9299
!data &&
93100
!schema?.default &&
94101
appliedUiSchemaOptions.NonFocusPlaceholder
95102
) {
96103
handleChange(path, appliedUiSchemaOptions.NonFocusPlaceholder);
97104
}
98-
}, [appliedUiSchemaOptions.NonFocusPlaceholder]);
105+
}, [appliedUiSchemaOptions.NonFocusPlaceholder]); */
99106

100-
const clearNonFocusPlaceholder = () => {
107+
/* const clearNonFocusPlaceholder = () => {
101108
if (data === appliedUiSchemaOptions.NonFocusPlaceholder) {
102109
handleChange(path, '');
103110
} else if (!data && !schema?.default) {
104111
handleChange(path, appliedUiSchemaOptions.NonFocusPlaceholder);
105112
}
106-
};
107-
108-
const [inputText, onChange] = useDebouncedChange(
109-
handleChange,
110-
schema?.default ?? '',
111-
data,
112-
path
113-
);
113+
}; */
114114

115115
return (
116116
<SpectrumProvider width={width}>
@@ -135,10 +135,10 @@ export const InputTextArea = React.memo(
135135
necessityIndicator={appliedUiSchemaOptions.necessityIndicator ?? null}
136136
onChange={onChange}
137137
type={appliedUiSchemaOptions.format ?? 'text'}
138-
validationState={isValidCheck()}
138+
validationState={isValidCheck ? 'valid' : 'invalid'}
139139
value={inputText}
140140
width={width}
141-
onFocusChange={clearNonFocusPlaceholder}
141+
//onFocusChange={clearNonFocusPlaceholder}
142142
/>
143143
</SpectrumProvider>
144144
);

0 commit comments

Comments
 (0)