Skip to content

Commit 4a90ac3

Browse files
committed
refactor number field events
1 parent f812272 commit 4a90ac3

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed

shesha-reactjs/src/designer-components/numberField/control.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ const NumberFieldControl: FC<IProps> = ({ disabled, model, onChange, value, onBl
4343
const [backgroundStyles, setBackgroundStyles] = useState({});
4444
const shadowStyles = useMemo(() => getShadowStyle(shadow), [shadow]);
4545

46-
console.log('model?.highPrecision', model?.highPrecision);
47-
4846
useEffect(() => {
4947
const fetchStyles = async () => {
5048
const storedImageUrl =
@@ -120,7 +118,6 @@ const NumberFieldControl: FC<IProps> = ({ disabled, model, onChange, value, onBl
120118
),
121119
};
122120

123-
console.log({ ...inputProps });
124121

125122
return (
126123
<ConfigProvider
@@ -138,7 +135,7 @@ const NumberFieldControl: FC<IProps> = ({ disabled, model, onChange, value, onBl
138135
<InputNumber
139136
value={value ?? model?.defaultValue}
140137
{...inputProps}
141-
stringMode={false}
138+
stringMode={!model?.highPrecision}
142139
style={{ ...finalStyle, ...jsStyle }}
143140
className={`sha-input ${styles.numberField}`}
144141
onBlur={onBlur}

shesha-reactjs/src/designer-components/numberField/numberField.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,6 @@ const NumberFieldComponent: IToolboxComponent<INumberFieldComponentProps> = {
5656
>
5757
{(value, onChange) => {
5858
const customEvents = getEventHandlers(model, allData);
59-
60-
const onChangeInternal = (...args: any[]) => {
61-
// Handle the case where the user clears the input
62-
if (args[0] === null) {
63-
// Fire custom event with `null` or fallback value
64-
customEvents.onChange({ target: { value: null } } as unknown as React.ChangeEvent<HTMLInputElement>);
65-
66-
if (typeof onChange === 'function') onChange(null);
67-
return;
68-
}
69-
70-
// Handle normal case where args[0] is a valid number
71-
customEvents.onChange({
72-
target: { value: args[0] },
73-
} as unknown as React.ChangeEvent<HTMLInputElement>);
74-
75-
if (typeof onChange === 'function') onChange(...args);
76-
};
77-
7859
return model.readOnly ? (
7960
<ReadOnlyDisplayFormItem
8061
type="number"
@@ -85,7 +66,7 @@ const NumberFieldComponent: IToolboxComponent<INumberFieldComponentProps> = {
8566
disabled={model.readOnly}
8667
model={model}
8768
value={value}
88-
onChange={onChangeInternal}
69+
onChange={onChange}
8970
onBlur={customEvents.onBlur}
9071
onFocus={customEvents.onFocus}
9172
/>

shesha-reactjs/src/designer-components/numberField/settingsForm.ts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,50 @@ export const getSettings = (data: INumberFieldComponentProps) => {
161161
defaultValue: false,
162162
})
163163

164-
.addSettingsInput({
165-
id: '874aa450-6274-48d4-8032-395fdd680fa5',
166-
inputType: 'numberField',
167-
propertyName: 'stepNumeric',
168-
parentId: 'jNmEKg7HtYXwaL9CylTOX',
169-
label: 'Step',
170-
defaultValue: 1,
171-
validate: {},
172-
settingsValidationErrors: [],
164+
.addSettingsInputRow({
165+
id: 'type-default-value-s4gmBg31azZC0UjZjpfTm',
166+
parentId: 's4gmBg31azZC0UjZjpfTm',
167+
readOnly: { _code: 'return getSettingValue(data?.readOnly);', _mode: 'code', _value: false } as any,
168+
hidden: {
169+
_code: 'return getSettingValue(data?.highPrecision)',
170+
_mode: 'code',
171+
_value: false,
172+
},
173+
inputs: [
174+
{
175+
id: '874aa450-6274-48d4-8032-395fdd680fa5',
176+
type: 'numberField',
177+
propertyName: 'stepNumeric',
178+
parentId: 'jNmEKg7HtYXwaL9CylTOX',
179+
label: 'Step',
180+
defaultValue: 1,
181+
validate: {},
182+
settingsValidationErrors: [],
183+
},
184+
],
185+
})
186+
187+
.addSettingsInputRow({
188+
id: 'type-default-value-s4gmBg31azZC0UjZjpfTm',
189+
parentId: 's4gmBg31azZC0UjZjpfTm',
190+
readOnly: { _code: 'return getSettingValue(data?.readOnly);', _mode: 'code', _value: false } as any,
191+
hidden: {
192+
_code: 'return !getSettingValue(data?.highPrecision)',
193+
_mode: 'code',
194+
_value: false,
195+
} as any,
196+
inputs: [
197+
{
198+
id: '874aa450-6274-48d4-8032-395fdd680fa5',
199+
type: 'textField',
200+
propertyName: 'stepString',
201+
parentId: 'jNmEKg7HtYXwaL9CylTOX',
202+
label: 'Step',
203+
defaultValue: 0.1,
204+
validate: {},
205+
settingsValidationErrors: [],
206+
},
207+
],
173208
})
174209

175210
.toJson(),
@@ -199,15 +234,15 @@ export const getSettings = (data: INumberFieldComponentProps) => {
199234
{
200235
type: 'numberField',
201236
id: 'minLength-s4gmBg31azZC0UjZjpfTm',
202-
propertyName: 'validate.minLength',
237+
propertyName: 'validate.minValue',
203238
label: 'Min Value',
204239
size: 'small',
205240
jsSetting: true,
206241
},
207242
{
208243
type: 'numberField',
209244
id: 'maxLength-s4gmBg31azZC0UjZjpfTm',
210-
propertyName: 'validate.maxLength',
245+
propertyName: 'validate.maxValue',
211246
label: 'Max Value',
212247
size: 'small',
213248
jsSetting: true,

0 commit comments

Comments
 (0)