Search code examples
google-app-maker

How to disable all elements of a form in appmaker without writing code for each element?


I have a form in appmaker which has many (atleast 20-25) input elements. I want to disable all of them through code without writing separate disable line code for each element.

I tried to use a for loop to do something like below but found no luck as its not right.

  for(var i=0; i< app.currentPage.descendants.Form1.children.length; i++) 
   {
     app.currentPage.descendants.Form1.children[0].enabled=false;
   }

Is there a way to disable them all at once?


Solution

  • This is untested, but try the following:

    var children = app.currentPage.descendants.Form1Body.children._values;
    
    for (var i in children) {
      children[i].enabled = false;
    }
    

    Note that I am using Form1Body instead of Form1 because the top Form element is made up of a header, body, and footer, so when looping over children of Form1 you are in fact referencing 3 separate panels instead of input elements.