Page 1 of 1

Multiple "if" statements inside a function

Posted: Tue Jul 09, 2013 5:53 am
by Tommy B

If i use this code on "page show" everything works great.

precode
setTimeout(function()
{
var eventNameMain = Appery ('eventNameLabel').text();
var monitorNameMain = Appery ('monitorInfoLabel').text();
var ihTechNameMain = Appery ('ihTechNameLabel').text()
if (eventNameMain.length === 0) {
Appery.navigateTo('NoDefaultSettings', {transition: 'pop'});
}
},1000);
/code/pre

My problem is that I need to do this "if" statement for all three var's. When i add this code it keeps navigating to the popup page. I also tried using the || option for an or statement but still no luck.

precode
setTimeout(function()
{

var eventNameMain = Appery ('eventNameLabel').text();
var monitorNameMain = Appery ('monitorInfoLabel').text();
var ihTechNameMain = Appery ('ihTechNameLabel').text()

Code: Select all

if (eventNameMain.length === 0) { 
  Appery.navigateTo('NoDefaultSettings', {transition: 'pop'}); 
 } 
if (monitorNameMain.length === 0) { 
  Appery.navigateTo('NoDefaultSettings', {transition: 'pop'}); 
 } 
if (ihTechNameMain.length === 0) { 
  Appery.navigateTo('NoDefaultSettings', {transition: 'pop'}); 
 } 

},1000);
/code/pre


Multiple "if" statements inside a function

Posted: Tue Jul 09, 2013 10:26 am
by Anton Artyukh5836028

Hi Tommy,

Try this:
precodesetTimeout( function() {
var eventNameMain = Appery( 'eventNameLabel' ).text();
var monitorNameMain = Appery( 'monitorInfoLabel' ).text();
var ihTechNameMain = Appery( 'ihTechNameLabel' ).text()

if ( !eventNameMain.length !monitorNameMain.length !ihTechNameMain.length ) {
Appery.navigateTo( 'NoDefaultSettings', {
transition: 'pop'
} );
}
}, 1000 );/code/pre


Multiple "if" statements inside a function

Posted: Tue Jul 09, 2013 8:54 pm
by Tommy B

Sorry that is not working either. The popup still activates even if there is text in the three label's that I am referencing.

Also, I added === 0 to the end of the "or" string and still no dice.

codeif ( !eventNameMain.length !monitorNameMain.length !ihTechNameMain.length === 0)/code


Multiple "if" statements inside a function

Posted: Tue Jul 09, 2013 9:20 pm
by Anton Artyukh5836028

Let's clarify -- you need show NoDefaultSettings screen when:

1) eventNameMain and monitorNameMain and ihTechNameMain is empty

2) any of this varible are empty

3) something else
?


Multiple "if" statements inside a function

Posted: Tue Jul 09, 2013 10:46 pm
by Tommy B

Yes number 1 is correct


Multiple "if" statements inside a function

Posted: Wed Jul 10, 2013 7:05 am
by Anton Artyukh5836028

Here is your code:

precodesetTimeout( function() {
var eventNameMain = Appery( 'eventNameLabel' ).text();
var monitorNameMain = Appery( 'monitorInfoLabel' ).text();
var ihTechNameMain = Appery( 'ihTechNameLabel' ).text()
if ( !eventNameMain.length && !monitorNameMain.length && !ihTechNameMain.length ) {
Appery.navigateTo( 'NoDefaultSettings', {
transition: 'pop'
} );
}
}, 1000 );/code/pre
You don't need compare with 0. If length is zero it's equivalent false. Instruction !Something is check and invert boolean value of something. && means and.
I think will be helpful for you: https://developer.mozilla.org/en-US/d...