1 year ago
#386779
Carlos Durán
Check when a form-field component is loaded in React based module
I've created a Liferay form-field module based on React.
I want to manipulate the component with Javascript but as the code fires when DOM is ready, but the component isn't, the code doesn't work.
The problem is that I'm trying to get a DOM element this way:
document.querySelector(".slider-divisor")
I've tried putting this line in many places of the JS file (resources/META-INF/resources/slider-form-field.es.js) but the result is always null.
I've found a solution using setInterval that checks when the component 'appears' in the DOM. Then, the code is executed and setInterval stops, but I want to know if exists a way to check an event when component is loaded to execute my code instead use setinterval.
This is command I've used to create the module:
blade create -t form-field -c SliderFormField --js-framework react -p com.liferay.dynamic.data.mapping.form.field.type.slider slider-form-field
Thanks in advance.
javascript
reactjs
liferay
liferay-7
0 Answers
Your Answer