diff --git a/client/src/pages/Devices.jsx b/client/src/pages/Devices.jsx index 0c1c191..d2357c5 100644 --- a/client/src/pages/Devices.jsx +++ b/client/src/pages/Devices.jsx @@ -586,13 +586,21 @@ const DeviceModal = ({ device, onClose, onSave }) => { await api.put(`/devices/${device.id}`, updateData); } else { - // Create new device - include all fields, convert empty strings to null + // Create new device - include all fields, handle empty values properly const createData = { ...formData }; + + // Convert empty strings to null for numeric fields, remove empty strings for optional string fields Object.keys(createData).forEach(key => { if (createData[key] === '') { - createData[key] = null; + if (['geo_lat', 'geo_lon', 'heartbeat_interval'].includes(key)) { + createData[key] = null; + } else if (['firmware_version', 'notes', 'location_description', 'name'].includes(key)) { + // Remove empty optional string fields instead of sending empty strings + delete createData[key]; + } } }); + await api.post('/devices', createData); } onSave();