I have a scenario where we will check if the image exists or not before the cell click event.
if an image exists we will enable the cell to perform a cell click event.
if not we have to disable the cell click to prevent events in react js.
to check the image we are calling external API.
please help me to achieve the results.
Hello,
Thank you for reaching out to us.
As for now, for us, the scenario looks similar to the following:
cellclick
event. If the image does not exist, ignore the handler of the cellclick
event.
If our assumption is correct, please see the following suggestion:
You can perform an image check inside the cellclick
handler and continue execution if the image exists. Otherwise, interrupt the execution by returning from the handler function.
We have prepared the JSFiddle to demonstrate this approach: https://jsfiddle.net/flexmonster/pmv0a89f/. It uses the mock function that replaces an external API and answers with a boolean depending on whether the "image" exists:
flexmonster.on("cellclick", cellClickHandler); //subscription to the event
function cellClickHandler(cell) {
if (!checkImage()) return; //check if image exists. If not, return from the function
alert("Handler executed"); //handler itself
}
function checkImage() { //mock function
return Math.random() > 0.5;
}
Please let us know if it helps.
If we did not understand you correctly, please provide us with additional details about the required functionality. It would be useful to receive a detailed scenario/step-by-step explanation.
We are looking forward to hearing from you.
Kind regards,
Illia
Hello,
We are reaching out to ask if the provided solution works for you.
Our team is looking forward to hearing your feedback.
Regards,
Illia
Hello,
We are curious if you had some time to check out the proposed solution.
Please let us know if any questions appear on this point.
Kind regards,
Illia