请有人帮忙回答一下:
我有2个NumberInput控件,一个输入,另一个被禁用。我需要在第一个输入字段中输入数字,禁用字段以显示此数字/ 100。这两个NumberInput将具有源字段,这些源字段将以simpleform格式保存到当前记录。
我如何在react-admin中执行此操作
谢谢
对于这个问题,我有一个简短的解决方案:我所做的就是在FormDataConsumer中进行计算。现在,我能够获得计算出的值,并且它更新了数组中的正确记录。
谢谢
<FormDataConsumer>
{({
formData, // The whole form data
scopedFormData, // The data for this item of the ArrayInput
getSource, // A function to get the valid source inside an ArrayInput
...rest
}) => {
if (typeof scopedFormData !== 'undefined') {
scopedFormData.total = scopedFormData.quantity * scopedFormData.unitprice;
return (
<NumberInput disabled defaultValue={scopedFormData.total} label="Total" source={getSource('total')} />
)
} else {
return(
<NumberInput disabled label="Total" source={getSource('total')} />
)
}
}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句