onChange trigger example with React

Recently, I faced the issue. There is a form with some fields. Each field has several functions; functions do something. For example, one function writes the field name and its value into the object. Then the customer asks to add the buttons with specified values. When the button is clicked, the relevant field should update its value.

Here is the trigger hack that calls the onChange function of that field.

function triggerInput(enteredName, enteredValue) {

  const input = document.getElementById(enteredName);

  const lastValue = input.value;

  input.value = enteredValue;

  const event = new Event("input", { bubbles: true });

  const tracker = input._valueTracker;

  if (tracker) {





Live example link

2868e927 153f 4f5c 96bf 8bf0187ba2a9 rectangle 400 x

Frontend Developer at JetRockets