remarkablemark / html-react-parser

📝 HTML to React parser.

Home Page:https://b.remarkabl.org/html-react-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loosing onclick functionality after parse

jasan-s opened this issue · comments

commented

see https://jsfiddle.net/kvgz36eh/.

notice that the onclick methods are lost post parsing , thus on click the hidden input field value is never updated.

commented

Thanks for opening the issue @jasan-s

The onclick not being set on the React element is actually expected behavior. (A similar issue was brought up in #53.)

Because there's an XSS security risk when evaling the onclick string, the property is not translated in the HTMLDOMPropertyConfig map.

The best solution is to use the replace option. See updated fiddle.

commented

@remarkablemark thanks for that, I realized the intentional removal of dirty html afterward. I solved it using the following :
const answer = document.querySelector('input[name="otpselection"]:checked').value;
although i like your solution as well.

@remarkablemark i think there should be an option for bypassing this. when a trusted backend sends html code, its much needed to handle event listners automatically

commented

@kasvith the recommended approach is to use the replace option. If you have any questions, feel free to open a new discussion or issue.