6
votes

I have a simple hidden input field in my React Redux-Form and the value of the field is set by some Google Tag Manager code that basically does document.getElementById('gtm_field').value = 'some value'

The onchange event never gets fired and therefore the value of the form field never gets set in my Redux store. What is the recommended way to approach this problem? Note that I can modify the GTM code that is added to the page do trigger HTML element events, but it has to be added 'outside' the context of my React app.

Is there a simple way to set the value of a redux-form input field from 'external' JS?

1

1 Answers

0
votes

You should use the function change() in redux-form props, it could change the value of a field in the Redux store. The usage like this:

handleChange() {    
  this.props.change(field:String, value:any)
}