Skip to content

Commit

Permalink
fix(form): Fix the issue of the ProFormMoney component causing duplic…
Browse files Browse the repository at this point in the history
…ate currency symbols when using trigger=onBlur

close #6779
  • Loading branch information
chenshuai2144 committed Jul 16, 2023
1 parent 76470d8 commit bc94215
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 602 deletions.
7 changes: 4 additions & 3 deletions packages/field/src/components/Digit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const FieldDigit: ProFieldFC<FieldDigitProps> = (
) {
val = Number(val.toFixed(fieldProps.precision));
}
return fieldProps?.onChange?.(val);
return val;
},
[fieldProps],
);
Expand Down Expand Up @@ -72,8 +72,9 @@ const FieldDigit: ProFieldFC<FieldDigitProps> = (
ref={ref}
min={0}
placeholder={placeholderValue}
{...omit(fieldProps, ['onChange'])}
onChange={proxyChange}
{...omit(fieldProps, ['onChange', 'onBlur'])}
onChange={(e) => fieldProps?.onChange?.(proxyChange(e))}
onBlur={(e) => fieldProps?.onBlur?.(proxyChange(e.target.value))}
/>
);
if (renderFormItem) {
Expand Down
14 changes: 14 additions & 0 deletions packages/field/src/components/Money/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ const FieldMoney: ProFieldFC<FieldMoneyProps> = (
'visible',
'open',
])}
onBlur={
fieldProps.onBlur
? (e) => {
let value = e.target.value;
if (moneySymbol && value) {
value = value.replace(
new RegExp(`\\${moneySymbol}\\s?|(,*)`, 'g'),
'',
);
}
fieldProps.onBlur?.(value);
}
: undefined
}
/>
);

Expand Down
2 changes: 1 addition & 1 deletion packages/form/src/components/FieldSet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const FieldSet: React.FC<ProFormFieldSetProps> = ({

const Wrapper: React.FC = useCallback(
({ children: dom }: { children?: React.ReactNode }) => (
<Components {...typeProps} {...(space as SpaceProps)} align="start">
<Components {...typeProps} {...(space as SpaceProps)} align="start" wrap>
{dom}
</Components>
),
Expand Down
1 change: 1 addition & 0 deletions packages/form/src/demos/money.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default () => {
locale="en-US"
initialValue={22.22}
min={0}
trigger="onBlur"
/>
<ProFormMoney
label="不限制金额大小"
Expand Down
Loading

0 comments on commit bc94215

Please sign in to comment.