Disable/enable cell click

Answered
Anusha A asked on March 25, 2021

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. 

3 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster March 26, 2021

Hello,
 
Thank you for reaching out to us.
 
As for now, for us, the scenario looks similar to the following:

  1. The user clicks on the cell.
  2. External API checks if the image exists.
  3. If the image exists, execute the handler of the 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

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster March 31, 2021

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

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster April 7, 2021

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

Please login or Register to Submit Answer