Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing React.js form values from a chrome extension

I'm not developing in React.js, but I'm working on a chrome extension that needs to programatically fill form values for different kinds of sites.

The site uses React.js, and I'm filling the value in the usual way with:

element = document.querySelector("input[name=firstName]");
element.value = "something";

When the user clicks the submit button, he gets this error for that form element, even if the element has a value: "This information is required."

It doesn't help if fire "change" event for that element.

evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
element.dispatchEvent(evt);

There is some method in the React.js framework I need to call to programatically change the value? Help from React.js experienced users is appreciated!

like image 383
Daniel Avatar asked Nov 08 '22 10:11

Daniel


1 Answers

I found a solution. Call element.select(); before changing the value.

like image 77
Daniel Avatar answered Nov 15 '22 07:11

Daniel