如何在ReferenceInput更改时更改DisabledInput的值

时间:2017-06-12 15:05:32

标签: admin-on-rest

我想在ReferenceInput onChange事件时为DisabledInput设置值。我

export const RegistersCreate=(props) => (
  <Create {...props}>
    <SimpleForm>
      <ReferenceInput source='member_id' reference='members' allowEmpty validate={required}>
        <SelectInput source='name'/>
      </ReferenceInput>
      <ReferenceInput source='package_id' reference='packages' allowEmpty validate={required}>
        <SelectInput source='name'/>
      </ReferenceInput>
      <ReferenceInput source='promotion_id' reference='promotions' allowEmpty>
        <SelectInput source='name'/>
      </ReferenceInput>
      <DateInput source='date_from' validate={required}/>
      <DateInput source='date_to' validate={required}/>
      <DisabledInput source='amount'/>
    </SimpleForm>
  </Create>
); // RegistersCreate

2 个答案:

答案 0 :(得分:2)

但是上面的建议并不完美,我尝试使用TextInputs(没有像你一样的ReferenceInput)并编写简单的类:

document.onreadystatechange = function(){
    if (document.readyState === "complete") {
       myFunction();
    }
    else {
       window.onload = function () {
          myFunction();
       };
    };
}

并导入import React from 'react'; import { Field } from 'redux-form'; import { TextInput, required, } from 'admin-on-rest'; export class ValueField extends React.Component { constructor(props) { super(props); this.state = { val1: parseInt(this.props.record.money_amount, 10), val2: parseInt(this.props.record.credit_limit, 10), }; } render(){ return ( <div> <Field name="money_amount" validate={required} component={TextInput} onChange={(e) => this.setState({ val1: parseInt(e.target.value, 10) }) }/> <Field name="credit_limit" component={TextInput} onChange={(e) => this.setState({ val2: parseInt(e.target.value, 10) }) } /> <span>{this.state.val1 + this.state.val2}</span> </div> ); }; } export default ValueField;

resources.js

...并将编辑视图添加为:

import ValueField from './ValueField';

就我而言,有<ValueField /> money_amount个字段。我需要计算这些字段的总和。

答案 1 :(得分:0)

aor命令为依赖于指定字段的字段创建了指定组件。希望它能帮助你。请检查链接: https://github.com/marmelab/aor-dependent-input