I'm having some trouble trying to dynamically change a TextInput value based on another input using FormDataConsumer.
I have a ReferenceInput that set an AutocompleteInput with some options like below:
<ReferenceInput id="nome" label="Portaauto" source="Portaauto" name="Portaauto" reference="acl-pegaProtocolosConhecidos" alwaysOn >
<AutocompleteInput id="protocolo" name="Portaautoinput" source="protocolo" translateChoice={false} optionText="nome" />
</ReferenceInput>
The backend returns this record:
[{"id":"http","nome":"http(80)","porta":"80","protocolo":"tcp"},
{"id":"https","nome":"https(443)","porta":"443","protocolo":"tcp"},
{"id":"ntp","nome":"ntp(123)","porta":"123","protocolo":"udp"},
{"id":"dns","nome":"dns(53)","porta":"53","protocolo":"udp"},
{"id":"custom","nome":"custom(10-100)","porta":"10-100","protocolo":"gre"}]
This input is working as expected but I need to change 2 other inputs using user selection. So, If a user selects "http", one input needs to have "80" and other input needs to have "tcp".
I've tried to change just one input in a simply way but I can't even set a TextInput value dynamically using the code below:
const getPortSugestion = (values) => {
console.log(values)
return values
};
<FormDataConsumer id="nome">
{({ formData, record, ...rest }) =>
<TextInput
name="city"
source={getPortSugestion(formData.Portaauto)}
value={getPortSugestion(formData.Portaauto)}
{...rest}
/>
}
</FormDataConsumer>
Using this code the "source" gets changed (with 'nome'), but the "value" isn't changed...
So, how can I change the TextInput value?
And How can I access other attributes from my record so I can change input values using other fields from my record ('porta' and 'protocolo')?
Can anybody help? Thanks in advance.