Skip to content

Commit 3ffa964

Browse files
fix: disable Generate button when required fields are not filled (#5927)
* fix: disable Generate button when required fields are not filled * add onBlur handler to Input component and simplify data handling in DocStoreInputHandler --------- Co-authored-by: Henry <hzj94@hotmail.com>
1 parent d923337 commit 3ffa964

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

packages/ui/src/ui-component/input/Input.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useTheme } from '@mui/material/styles'
55
import SelectVariable from '@/ui-component/json/SelectVariable'
66
import { getAvailableNodesForVariable } from '@/utils/genericHelper'
77

8-
export const Input = ({ inputParam, value, nodes, edges, nodeId, onChange, disabled = false }) => {
8+
export const Input = ({ inputParam, value, nodes, edges, nodeId, onChange, onBlur, disabled = false }) => {
99
const theme = useTheme()
1010
const [myValue, setMyValue] = useState(value ?? '')
1111
const [anchorEl, setAnchorEl] = useState(null)
@@ -70,6 +70,9 @@ export const Input = ({ inputParam, value, nodes, edges, nodeId, onChange, disab
7070
setMyValue(e.target.value)
7171
onChange(e.target.value)
7272
}}
73+
onBlur={(e) => {
74+
if (onBlur) onBlur(e.target.value)
75+
}}
7376
inputProps={{
7477
step: inputParam.step ?? 1,
7578
style: {
@@ -106,6 +109,9 @@ export const Input = ({ inputParam, value, nodes, edges, nodeId, onChange, disab
106109
setMyValue(e.target.value)
107110
onChange(e.target.value)
108111
}}
112+
onBlur={(e) => {
113+
if (onBlur) onBlur(e.target.value)
114+
}}
109115
inputProps={{
110116
step: inputParam.step ?? 1,
111117
style: {
@@ -153,6 +159,7 @@ Input.propTypes = {
153159
inputParam: PropTypes.object,
154160
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
155161
onChange: PropTypes.func,
162+
onBlur: PropTypes.func,
156163
disabled: PropTypes.bool,
157164
nodes: PropTypes.array,
158165
edges: PropTypes.array,

packages/ui/src/views/docstore/DocStoreInputHandler.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ const DocStoreInputHandler = ({ inputParam, data, disabled = false, onNodeDataCh
4141

4242
const handleDataChange = ({ inputParam, newValue }) => {
4343
data.inputs[inputParam.name] = newValue
44-
const allowedShowHideInputTypes = ['boolean', 'asyncOptions', 'asyncMultiOptions', 'options', 'multiOptions']
45-
if (allowedShowHideInputTypes.includes(inputParam.type) && nodeDataChangeHandler) {
44+
if (nodeDataChangeHandler) {
4645
nodeDataChangeHandler({ nodeId: data.id, inputParam, newValue })
4746
}
4847
}
@@ -157,7 +156,7 @@ const DocStoreInputHandler = ({ inputParam, data, disabled = false, onNodeDataCh
157156
<File
158157
disabled={disabled}
159158
fileType={inputParam.fileType || '*'}
160-
onChange={(newValue) => (data.inputs[inputParam.name] = newValue)}
159+
onChange={(newValue) => handleDataChange({ inputParam, newValue })}
161160
value={data.inputs[inputParam.name] ?? inputParam.default ?? 'Choose a file to upload'}
162161
/>
163162
)}
@@ -174,7 +173,7 @@ const DocStoreInputHandler = ({ inputParam, data, disabled = false, onNodeDataCh
174173
columns={inputParam.datagrid}
175174
hideFooter={true}
176175
rows={data.inputs[inputParam.name] ?? JSON.stringify(inputParam.default) ?? []}
177-
onChange={(newValue) => (data.inputs[inputParam.name] = newValue)}
176+
onChange={(newValue) => handleDataChange({ inputParam, newValue })}
178177
/>
179178
)}
180179
{inputParam.type === 'code' && (
@@ -200,6 +199,7 @@ const DocStoreInputHandler = ({ inputParam, data, disabled = false, onNodeDataCh
200199
disabled={disabled}
201200
inputParam={inputParam}
202201
onChange={(newValue) => (data.inputs[inputParam.name] = newValue)}
202+
onBlur={(newValue) => handleDataChange({ inputParam, newValue })}
203203
value={data.inputs[inputParam.name] ?? inputParam.default ?? ''}
204204
nodeId={data.id}
205205
/>

0 commit comments

Comments
 (0)