Note that there are some explanatory texts on larger screens.

plurals
  1. POPass values to a function called from an If Statement?
    primarykey
    data
    text
    <p>I'm creating a form in UiApp to collect user data. Based on their answers on page, I need to go to page based answer. Say I've got three pages. The user completes first page. I use a button and serverhandler to call a function that runs and if statement like:</p> <pre><code>if(value1 == s1 &amp;&amp; value2 == s2){ app.getElementById('page1').setVisible(false); app.getElementById('page2').setVisible(true); } </code></pre> <p>This works fine. I'm on page two. From there the click for on the next button and that calls a syncText' function that will load the user data with this method: <a href="https://stackoverflow.com/questions/12041841/how-to-allow-users-to-review-answers-before-submiting-form">How To Allow Users to Review Answers before Submiting Form?</a></p> <p>All good. The problem comes when I am on page one and I need to go to page three and syncText. </p> <pre><code>if( value1 != s1){ app.getElementById('page1').setVisible(false); app.getElementById('page3').setVisible(true); syncText() } </code></pre> <p>This does not work. How can I call a function in an If Statement in Google's UiApp?</p> <p>I know I could simply rewrite the function into that if statement, but my true form is far more complicated and I want to avoid repeating myself. Any Help?</p> <hr> <p>Updated: So it looks like the function is being called but it can't find the values from the form. How do I get the form values into this function? </p> <p>Here's a full example code:</p> <pre><code>function doGet(e){ var app = UiApp.createApplication(); var appPanel = app.createVerticalPanel(); var form = app.createFormPanel(); var panel1 = app.createGrid(4,5).setId('panel1'); var firstNameLabel = app.createLabel("First Name:"); var firstName = app.createTextBox().setName('firstName').setId('firstName'); var lastNameLabel = app.createLabel("Last Name:"); var lastName = app.createTextBox().setName('lastName').setId('lastName'); var emailLabel = app.createLabel('Your Email'); var email = app.createTextBox().setName('email').setId('email'); var testing = app.createServerHandler('testing').addCallbackElement(form); var button1 = app.createButton('Go to Review'); var info1 = app.createLabel("Please Enter First Name") .setVisible(false) .setStyleAttribute('color', 'red'); var info2 = app.createLabel("Please Enter Last Name") .setVisible(false) .setStyleAttribute('color', 'red'); var info3 = app.createLabel("Please Enter Email") .setVisible(false) .setStyleAttribute('color', 'red'); panel1.setWidget(0,0, firstNameLabel); panel1.setWidget(0,1, firstName); panel1.setWidget(0,2, lastNameLabel); panel1.setWidget(0,3, lastName); panel1.setWidget(1,1, info1); panel1.setWidget(1,3, info2); panel1.setWidget(2,0, emailLabel); panel1.setWidget(2,1, email); panel1.setWidget(2,3, button1); panel1.setWidget(3,1, info3); app.add(form); appPanel.add(panel1); form.add(appPanel); var panel2 = app.createGrid(4,5).setId('panel2').setVisible(false); var reviewFirstNameLabel = app.createLabel("First Name:"); var reviewFirstName = app.createLabel().setId('reviewFirstName'); var reviewLastNameLabel = app.createLabel("Last Name:"); var reviewLastName = app.createLabel().setId('reviewLastName'); var reviewEmailLabel = app.createLabel('Your Email:'); var reviewEmail = app.createLabel().setId('reviewEmail'); var submitButton = app.createSubmitButton('Submit'); var button2 = app.createButton('Edit Response'); panel2.setWidget(0,0, reviewFirstNameLabel); panel2.setWidget(0,1, reviewFirstName); panel2.setWidget(0,2, reviewLastNameLabel); panel2.setWidget(0,3, reviewLastName); panel2.setWidget(1,0, reviewEmailLabel); panel2.setWidget(1,1, reviewEmail); panel2.setWidget(2,0, button2); panel2.setWidget(3,0, submitButton); appPanel.add(panel2); // var editResponse = app.createClientHandler() .forTargets(panel1).setVisible(true) .forTargets(panel2).setVisible(false); button1.addClickHandler(testing); button2.addClickHandler(editResponse); return app; } function syncText(e){ var app = UiApp.getActiveApplication(); app.getElementById('reviewFirstName').setText(e.parameter.firstName)); app.getElementById('reviewLastName').setText(e.parameter.lastName); app.getElementById('reviewEmail').setText(e.parameter.email); app.getElementById('panel1').setVisible(false); app.getElementById('panel2').setVisible(true); return app; } function testing(e){ var app = UiApp.getActiveApplication(); var firstName = e.parameter.firstName; var lastName = e.parameter.lastName; var email = e.parameter.email; if(firstName != ""){ syncText(); } </code></pre> <p>The error now says the parameter is undefined? All of the values form the testing function check out, but I can't seem to get the values from syncText(). Any help on getting this functional?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload