Skip to content

Commit a569e37

Browse files
authored
fix(ui): Send number input as number JSON not string (mudler#130)
* fix(ui): Submit number fields as numbers not text * fix(ui): Remove some debug messages
1 parent 1eee5b5 commit a569e37

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

webui/react-ui/src/components/AgentForm.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,24 @@ const AgentForm = ({
2828

2929
// Handle input changes
3030
const handleInputChange = (e) => {
31-
const { name, value, type, checked } = e.target;
31+
const { name, value, type, checked } = e.target.name.target;
32+
33+
// Convert value to number if it's a number input
34+
const processedValue = type === 'number' ? Number(value) : value;
3235

3336
if (name.includes('.')) {
3437
const [parent, child] = name.split('.');
3538
setFormData({
3639
...formData,
3740
[parent]: {
3841
...formData[parent],
39-
[child]: type === 'checkbox' ? checked : value
42+
[child]: type === 'checkbox' ? checked : processedValue
4043
}
4144
});
4245
} else {
4346
setFormData({
4447
...formData,
45-
[name]: type === 'checkbox' ? checked : value
48+
[name]: type === 'checkbox' ? checked : processedValue
4649
});
4750
}
4851
};
@@ -57,7 +60,6 @@ const AgentForm = ({
5760

5861
// Handle navigation between sections
5962
const handleSectionChange = (section) => {
60-
console.log('Changing section to:', section);
6163
setActiveSection(section);
6264
};
6365

@@ -94,7 +96,6 @@ const AgentForm = ({
9496
};
9597

9698
const handleAddDynamicPrompt = () => {
97-
console.log('Adding dynamic prompt');
9899
setFormData({
99100
...formData,
100101
dynamicPrompts: [

webui/react-ui/src/components/ConfigForm.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ const ConfigForm = ({
5757
};
5858

5959
// Handle config field change
60-
const handleConfigChange = (index, key, value) => {
60+
const handleConfigChange = (index, e) => {
61+
const { name: key, value, type, checked } = e.target;
6162
const item = items[index];
6263
const config = parseConfig(item);
63-
config[key] = value;
64+
65+
// Convert value to number if it's a number input
66+
const processedValue = type === 'number' ? Number(value) : value;
67+
68+
config[key] = type === 'checkbox' ? checked : processedValue;
6469

6570
onChange(index, {
6671
...item,
@@ -112,7 +117,7 @@ const ConfigForm = ({
112117
<FormFieldDefinition
113118
fields={fieldGroup.fields}
114119
values={parseConfig(item)}
115-
onChange={(key, value) => handleConfigChange(index, key, value)}
120+
onChange={(e) => handleConfigChange(index, e)}
116121
idPrefix={`${itemType}-${index}-`}
117122
/>
118123
)}

webui/react-ui/src/components/agent-form-sections/MCPServersSection.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ const MCPServersSection = ({
2828
];
2929

3030
// Handle field value changes for a specific server
31-
const handleFieldChange = (index, name, value) => {
32-
handleMCPServerChange(index, name, value);
31+
const handleFieldChange = (index, e) => {
32+
const { name, value, type, checked } = e.target;
33+
34+
// Convert value to number if it's a number input
35+
const processedValue = type === 'number' ? Number(value) : value;
36+
37+
handleMCPServerChange(index, name, type === 'checkbox' ? checked : processedValue);
3338
};
3439

3540
return (
@@ -56,7 +61,7 @@ const MCPServersSection = ({
5661
<FormFieldDefinition
5762
fields={getServerFields()}
5863
values={server}
59-
onChange={(name, value) => handleFieldChange(index, name, value)}
64+
onChange={(e) => handleFieldChange(index, e)}
6065
idPrefix={`mcp_server_${index}_`}
6166
/>
6267
</div>

webui/react-ui/src/components/common/FormField.jsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import React from 'react';
1616
*/
1717
const FormField = ({
1818
id,
19+
name,
1920
label,
2021
type = 'text',
2122
value,
@@ -45,8 +46,9 @@ const FormField = ({
4546
<input
4647
type="checkbox"
4748
id={id}
49+
name={name}
4850
checked={value === true || value === 'true'}
49-
onChange={(e) => onChange(e.target.checked ? 'true' : 'false')}
51+
onChange={onChange}
5052
/>
5153
{labelWithIndicator}
5254
</label>
@@ -59,8 +61,9 @@ const FormField = ({
5961
<label htmlFor={id}>{labelWithIndicator}</label>
6062
<select
6163
id={id}
64+
name={name}
6265
value={value || ''}
63-
onChange={(e) => onChange(e.target.value)}
66+
onChange={onChange}
6467
className="form-control"
6568
required={required}
6669
>
@@ -79,8 +82,9 @@ const FormField = ({
7982
<label htmlFor={id}>{labelWithIndicator}</label>
8083
<textarea
8184
id={id}
85+
name={name}
8286
value={value || ''}
83-
onChange={(e) => onChange(e.target.value)}
87+
onChange={onChange}
8488
className="form-control"
8589
placeholder={placeholder}
8690
required={required}
@@ -96,8 +100,9 @@ const FormField = ({
96100
<input
97101
type="number"
98102
id={id}
103+
name={name}
99104
value={value || ''}
100-
onChange={(e) => onChange(e.target.value)}
105+
onChange={onChange}
101106
className="form-control"
102107
placeholder={placeholder}
103108
required={required}
@@ -115,8 +120,9 @@ const FormField = ({
115120
<input
116121
type={type}
117122
id={id}
123+
name={name}
118124
value={value || ''}
119-
onChange={(e) => onChange(e.target.value)}
125+
onChange={onChange}
120126
className="form-control"
121127
placeholder={placeholder}
122128
required={required}

webui/react-ui/src/components/common/FormFieldDefinition.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ const FormFieldDefinition = ({
2525
<div key={field.name} style={{ marginBottom: '16px' }}>
2626
<FormField
2727
id={`${idPrefix}${field.name}`}
28+
name={field.name}
2829
label={field.label}
2930
type={field.type}
3031
value={safeValues[field.name] !== undefined ? safeValues[field.name] : field.defaultValue}
31-
onChange={(value) => onChange(field.name, value)}
32+
onChange={onChange}
3233
placeholder={field.placeholder || ''}
3334
helpText={field.helpText || ''}
3435
options={field.options || []}

0 commit comments

Comments
 (0)