Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React component event fire manually from client side browser console


In my website, I have created a div element using React Js and it's editable, here if the user edits the content it will trigger the onInput function.
r.createElement("div", {
                dangerouslySetInnerHTML: {
                    __html: e
                },
                dir: "auto",
                ref: "input",
                spellCheck: this.props.spellCheck,
                "data-tab": this.props.editable ? 1 : null ,
                contentEditable: this.props.editable,
                className: t,
                onInput: this.onInput,
                onPaste: this.onPaste,
                onCut: this.onCut,
                onKeyUp: this.onKeyUp,
                onKeyPress: this.onKeyPress,
                onMouseDown: this.onMouseDown,
                onContextMenu: this.onContextMenu,
                onFocus: this.props.onFocus,
                onBlur: this.props.onBlur
            }

I am trying to set the content to that element from the client chrome browser console and it's not triggering the onInput event.

Is there a way to add input dynamically and call onInput event which is attached for the element?

like image 755
Suresh Pattu Avatar asked Feb 17 '26 14:02

Suresh Pattu


1 Answers

you can dispatch event from console

1.find dom node through querySelector.. , or select element in "Elements" tab and use $0;

const input = document.querySelector('[contentEditable]');

2.create event

const eventX = new Event('input', {bubbles: true});

3.change value

input.textContent = "TEST";

4.dispatch event

input.dispatchEvent(eventX)

jsfiddle DEMO test

enter image description here

like image 119
Kokovin Vladislav Avatar answered Feb 19 '26 02:02

Kokovin Vladislav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!