Skip to content

Commit 349986e

Browse files
fix number input 'allow null value' has no effect
1 parent d7daf28 commit 349986e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

client/packages/lowcoder/src/comps/comps/numberInputComp/numberInputComp.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { BoolControl } from "comps/controls/boolControl";
1111
import { dropdownControl } from "comps/controls/dropdownControl";
1212
import { LabelControl } from "comps/controls/labelControl";
13-
import { numberExposingStateControl } from "comps/controls/codeStateControl";
13+
import { numberExposingStateControl, stringExposingStateControl } from "comps/controls/codeStateControl";
1414
import NP from "number-precision";
1515

1616
import {
@@ -234,6 +234,7 @@ const UndefinedNumberControl = codeControl<number | undefined>((value: any) => {
234234
});
235235

236236
const childrenMap = {
237+
defaultValue: stringExposingStateControl("defaultValue"), // It is more convenient for string to handle various states, save raw input here
237238
value: numberExposingStateControl("value"), // It is more convenient for string to handle various states, save raw input here
238239
placeholder: StringControl,
239240
disabled: BoolCodeControl,
@@ -261,6 +262,17 @@ const childrenMap = {
261262

262263
const CustomInputNumber = (props: RecordConstructorToView<typeof childrenMap>) => {
263264
const ref = useRef<HTMLInputElement | null>(null);
265+
const defaultValue = props.defaultValue.value;
266+
267+
useEffect(() => {
268+
let value = 0;
269+
if (defaultValue === 'null' && props.allowNull) {
270+
value = NaN;
271+
} else if (!isNaN(Number(defaultValue))) {
272+
value = Number(defaultValue);
273+
}
274+
props.value.onChange(value);
275+
}, [defaultValue]);
264276

265277
const formatFn = (value: number) =>
266278
format(value, props.allowNull, props.formatter, props.precision, props.thousandsSeparator);
@@ -271,7 +283,9 @@ const CustomInputNumber = (props: RecordConstructorToView<typeof childrenMap>) =
271283
const oldValue = props.value.value;
272284
const newValue = parseNumber(tmpValue, props.allowNull);
273285
props.value.onChange(newValue);
274-
oldValue !== newValue && props.onEvent("change");
286+
if((oldValue !== newValue)) {
287+
props.onEvent("change");
288+
}
275289
};
276290

277291
useEffect(() => {
@@ -363,7 +377,7 @@ const NumberInputTmpComp = (function () {
363377
.setPropertyViewFn((children) => (
364378
<>
365379
<Section name={sectionNames.basic}>
366-
{children.value.propertyView({ label: trans("prop.defaultValue") })}
380+
{children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
367381
{placeholderPropertyView(children)}
368382
{children.formatter.propertyView({ label: trans("numberInput.formatter") })}
369383
</Section>

client/packages/lowcoder/src/comps/controls/dropdownControl.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export function dropdownAbstractControl<T extends OptionsType>(
9696
value={this.value}
9797
options={finalOptions}
9898
onChange={(value) => {
99-
console.log(value);
10099
if (!params.disableDispatchValueChange) {
101100
this.dispatchChangeValueAction(value);
102101
}

0 commit comments

Comments
 (0)