自动计算输入字段 [英] Auto Calculate Input Fields

查看:52
本文介绍了自动计算输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人帮忙回答这个问题:

Please could someone help answer this:

我有 2 个 NumberInput 控件,一个输入,另一个被禁用.我需要在第一个输入字段中输入数字,禁用字段以显示此数字/100.这两个 NumberInput 将有源字段,这些字段将以简单形式保存到当前记录中.

I have 2 NumberInput controls, one input and the other is disabled. I need to input number in the first input field, the disabled field to show this number/100. The two NumberInput will have source fields that will save to the current record in the simpleform.

我如何在 react-admin 中执行此操作

How do I do this in react-admin

谢谢

推荐答案

我得到了一个更简短的解决方案:我所做的只是在 FormDataConsumer 中进行计算.现在,我能够获取计算值并更新数组中的正确记录.

I got a shorter solution to this question: All I did was to do the calculation within FormDataConsumer. Now, I am able to get the calculated value and it updates the correct record in the array.

谢谢

<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')} />
      )
    }            
  }} 

这篇关于自动计算输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆