简体   繁体   中英

Can I limit an onEdit function to a checkbox cell in Google Sheets?

I'm creating a spreadsheet in Google Sheets to collect and analyse individual inputs. The idea was to have users input data on the first sheet, hit a Submit button, and have it collected in another sheet, while clearing the first sheet inputs. I figured it out with a button, but I learned afterwards that buttons don't work on mobile, which will be the main method of use.

So, I'm wondering if there's a way to limit an 'onEdit' function to a single checkbox. ie I'd like to fill in the info without any functions going off, then when the user is ready, click the checkbox to send the info, which then sets the checkbox to false, and resets the input cells.

Is this possible?

You could use something like this:

function onEdit(e) {
  if(e.range.getSheet().getName()=='Sheet8') {
    if(e.range.getA1Notation()=='A1' && e.value=="TRUE") {
      SpreadsheetApp.getUi().alert('You Clicked A1. You have less than 30 seconds to run a function here');
      e.range.setValue("FALSE");
      //you less than 30 seconds to run a function here
    }
    if(e.range.getA1Notation()=='A2' && e.value=="TRUE") {
      SpreadsheetApp.getUi().alert('You Clicked A2. You have less than 30 seconds to run a function here');
      e.range.setValue("FALSE");
      //you less than 30 seconds to run a function here
    }
    if(e.range.getA1Notation()=='A3' && e.value=="TRUE") {
      SpreadsheetApp.getUi().alert('You Clicked A3. You have less than 30 seconds to run a function here.');
      e.range.setValue("FALSE");
      //you less than 30 seconds to run a function here
    }
  }else{
    return;
  }
}

To use this you need to insert checkboxes in A1,A2 and A3. You can add functions as shown in the code but the onEdit(e) has to complete in 30 seconds.

Personally, I would use a custom dialog to do what you are doing. In that way, I have many more options since I have all the events of any html page and there's no need to use onEdit() at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM