Search code examples
google-app-maker

Need some help assigning answer to google app maker form


on a google app maker form, How do you assign an answer to a question based on another answer or if the question is blank.

for example the time entry form question asks for the date of the entry, if it is blank how do i make the answer todays date?

Picture Question


Solution

  • Based on your use case I would suggest the following:

    Datebox widget>events>onAttach event enter the following code:

    var today = new Date();
    widget.value = new Date(today.getFullYear(), today.getMonth(), today.getDate());
    

    Then enter the following in the onClick event of your 'Submit button', this will repopulate the datebox widget after a new entry was successfully submitted:

    widget.datasource.createItem(function() {
      var today = new Date();
      widget.datasource.item.Date = new Date(today.getFullYear(), today.getMonth(), today.getDate());
    });