[英]Is there any function to get form value in react-final-form
[英]Conditionally format value in React-Final-Form based on data in form?
我正在以反應最終形式顯示貨幣值。 我在現場使用格式功能。
const formatMoney = (value) => {
if (!value) return value;
const formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
minimumFractionDigits: 2,
currency: 'USD'
});
return formatter.format(value);
};
問題是貨幣是表單中的另一個選項。 我看不到一種干凈的方法來訪問格式函數中的其余值。
問完問題后,我想出了解決方法,將值傳遞到表單的render函數中,然后傳遞給format函數,如下所示:
<Field
name="total"
type="text"
readOnly
component={LabeledInput}
placeholder="10"
label="Total"
help="Estimated total including tax"
format={v => formatMoney(v, values.currency)}
/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.