Skip to content
Advertisement

Google Apps Script validation issue in Google UiApp

I have been trying to figure out Google Apps Script validation in Google Sites and have yet to make the validation part work correctly.

I need to validate 2 things:

  1. That there is at least 5 characters in the “location” textbox (up to 100)
  2. That a date has been selected from the dropdown

If both conditions are not met, then it should make visible 2 things:

  1. warnException
  2. warnExceptionMes

That’s it.

The rest of my logic is working great. I am just starting out.

The full logic is listed below. I have replaced our domain info with xxxxxxxxx.

So far, it either never shows the messages and does nothing or just getting one of the items right allows it to move forward. They should both meet the requirements or the warnExceptions should be thrown. This would also be the same if a user loaded the page and did not fill either/or area out and just pushed the button.

How can I validate the Location textbox and the dateBox?

JavaScript

Advertisement

Answer

Try like this (see below) I changed a bit the validations and separated in 2 handlers + added a “clear” handler to be able to click-to-delete the warnings… test code here

You have also to add something to clear the warnings in the server handler and, why not combine the image and text warning in a single widget ? (easier to clean)

code below :

JavaScript

EDIT second version following your comment. I simulated a server function that takes some time so you see all the steps. + I combined the warning as suggested. (demo code updated with version 2)

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement