Skip to content

Commit 0d99720

Browse files
committed
fix(example): number input
1 parent a7e113a commit 0d99720

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

example/src/components/maptConfigDialog/MapConfigDialog.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,11 @@ export default function MapConfigDialog<T>({
168168
...(prev as any),
169169
[key]:
170170
type === 'number'
171-
? value === '' || isNaN(Number(value))
171+
? value === ''
172172
? undefined
173-
: Number(value)
173+
: /^-?\d*\.?\d*$/.test(value)
174+
? value
175+
: prev[key]
174176
: value,
175177
}));
176178
};
@@ -193,6 +195,22 @@ export default function MapConfigDialog<T>({
193195
}
194196
}
195197
}
198+
for (const f of autoSchema) {
199+
const k = String(f.key);
200+
if (f.type === 'number') {
201+
const val = updated[k];
202+
if (val === '' || val == null) {
203+
updated[k] = undefined;
204+
} else if (typeof val === 'string') {
205+
const parsed = Number(val.replace(',', '.'));
206+
if (isNaN(parsed)) {
207+
Alert.alert('Validation Error', `${f.label ?? k}: Invalid number`);
208+
return;
209+
}
210+
updated[k] = parsed;
211+
}
212+
}
213+
}
196214
if (validator) {
197215
const [err, value] = validate(updated, validator);
198216
if (err) {
@@ -348,7 +366,9 @@ export default function MapConfigDialog<T>({
348366
<View key={k} style={styles.field}>
349367
<Text style={styles.label}>{label}</Text>
350368
<TextInput
351-
keyboardType={f.type === 'number' ? 'numeric' : 'default'}
369+
keyboardType={
370+
f.type === 'number' ? 'decimal-pad' : 'default'
371+
}
352372
value={value?.toString() ?? ''}
353373
onChangeText={(v) => updateField(key, v, f.type)}
354374
placeholder={f.placeholder ?? label}

0 commit comments

Comments
 (0)