cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
David998721
Level: Powered On

First condition in If statement is triggering even when other conditions are met.

Hello. I am trying to use a dropdown box to create a sort of pagination for my app. However I am having an issue where it is navigating to the first screen which should only be triggered by the first condition, regardless of what condition is met. 
Here is the if statement in the 'OnChange' property of the drop down box. (The box is titled Pagination)

 

If(Pagination.Selected.Value = "1", Navigate(scrAddNomCore, ScreenTransition.None), Pagination.Selected.Value = "2", Navigate(scrAddNomKeyInfo, ScreenTransition.None),Pagination.Selected.Value = "3", Navigate(scrAddNomDetails, ScreenTransition.None), Pagination.Selected.Value = "4", Navigate(scrAddNomCitations, ScreenTransition.None), Pagination.Selected.Value = "5", Navigate(scrAddNomRanking, ScreenTransition.None), Pagination.Selected.Value = "6", Navigate(scrAddNomProposer, ScreenTransition.None), Pagination.Selected.Value = "7", Navigate(scrAddNomValidation, ScreenTransition.None), Pagination.Selected.Value = "7", Navigate(scrAddNomValidation, ScreenTransition.None), Pagination.Selected.Value = "8", Navigate(scrAddNomAttachments, ScreenTransition.None), false)

 

The Items property of the drop down box is: [1,2,3,4,5,6,7,8]

 

It is navigating to the first screen regardless of what value is changed.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: First condition in If statement is triggering even when other conditions are met.

@David998721good suggestions above.  I personally like the gallery based navigation, but if dropdown is the thing, that's fine too.

Also, you might want to consider two other things.

1) Use a Switch statement rather than a bunch of If statements this would be a little cleaner to troubleshoot.

Switch(Pagination.Selected.Value 
  1, Navigate(scrAddNomCore, ScreenTransition.None), 
  2, Navigate(scrAddNomKeyInfo, ScreenTransition.None),
  3, Navigate(scrAddNomDetails, ScreenTransition.None), 
  4, Navigate(scrAddNomCitations, ScreenTransition.None), 
  5, Navigate(scrAddNomRanking, ScreenTransition.None), 
  6, Navigate(scrAddNomProposer, ScreenTransition.None), 
  7, Navigate(scrAddNomValidation, ScreenTransition.None), 
  8, Navigate(scrAddNomAttachments, ScreenTransition.None))

 

2) - since you are going to probably use this on every page, you will be faced with copy and past and then, if you need changes...go fix all the places.  This can be prone to error.

You might want to check out this posting on how to avoid that in your Apps.

 

Hope this all helps.

 

 

6 REPLIES 6
iAm_ManCat
Level 10

Re: First condition in If statement is triggering even when other conditions are met.

Hello!

 

Firstly have you considered using a gallery with data source [1,2,3,4,5,6,7,8], and a label with ThisItem.Value that way you can have the numbers display along the top like page numbers that users are used to rather than a dropdown:

image.png

Then you have your Onselect set a variable, maybe called ChosenPage (So that it's not reliant on the gallery on that particular page for it's value)

image.png

 

And then expand your onselect formula for the pages:

image.png

I've attached the POC app as well,

 

The principle for Dropdowns is the same - I would have it set a variable that is used to navigate rather than relying on the .selected between pages.

NigelP
Level 8

Re: First condition in If statement is triggering even when other conditions are met.

Hi @David998721 

 

Try putting brackets around Pagination.Selected.Value = "1" and all of the other ones.

 

I have had this problem before with not putting brackets around everything.

 

Regards

 

Nigel

iAm_ManCat
Level 10

Re: First condition in If statement is triggering even when other conditions are met.

You should definitely not have to bracket the logic unless it explicitly requires brackets. It's nice to compartmentalize them that way, but it's not a requirement.

 

So what I would hazard a guess is happening in your App currently is that on the other pages you have a control with a different name - so when you then click that control, it is navigating to page 1, as your control called Pagination on page 1 still has a selected value of 1.

 

This is why I'd suggest using variables - you can't refer to a control on another page when you are changing a control on a separate page.

 

Also you have a 7 check twice in your formula Smiley Happy

Super User
Super User

Re: First condition in If statement is triggering even when other conditions are met.

@David998721good suggestions above.  I personally like the gallery based navigation, but if dropdown is the thing, that's fine too.

Also, you might want to consider two other things.

1) Use a Switch statement rather than a bunch of If statements this would be a little cleaner to troubleshoot.

Switch(Pagination.Selected.Value 
  1, Navigate(scrAddNomCore, ScreenTransition.None), 
  2, Navigate(scrAddNomKeyInfo, ScreenTransition.None),
  3, Navigate(scrAddNomDetails, ScreenTransition.None), 
  4, Navigate(scrAddNomCitations, ScreenTransition.None), 
  5, Navigate(scrAddNomRanking, ScreenTransition.None), 
  6, Navigate(scrAddNomProposer, ScreenTransition.None), 
  7, Navigate(scrAddNomValidation, ScreenTransition.None), 
  8, Navigate(scrAddNomAttachments, ScreenTransition.None))

 

2) - since you are going to probably use this on every page, you will be faced with copy and past and then, if you need changes...go fix all the places.  This can be prone to error.

You might want to check out this posting on how to avoid that in your Apps.

 

Hope this all helps.

 

 

iAm_ManCat
Level 10

Re: First condition in If statement is triggering even when other conditions are met.

ooOooooH! I like it! Toggle-based actioning of any stored code - that will be really useful, thanks for the idea Smiley Happy

Highlighted
Community Support Team
Community Support Team

Re: First condition in If statement is triggering even when other conditions are met.

Hi @David998721 ,

Could you please share a bit more about your issue?

Do you mean that the first condition in your If function always be true, regardless of other conditions are met?

 

I have made a test on my side, and don't have the issue that you mentioned. Please consider take a try to modify your formula as below:

If(
Pagination.Selected.Value = "1",
Navigate(scrAddNomCore, ScreenTransition.None),
Pagination.Selected.Value = "2",
Navigate(scrAddNomKeyInfo, ScreenTransition.None),
Pagination.Selected.Value = "3",
Navigate(scrAddNomDetails, ScreenTransition.None),
Pagination.Selected.Value = "4",
Navigate(scrAddNomCitations, ScreenTransition.None),
Pagination.Selected.Value = "5",
Navigate(scrAddNomRanking, ScreenTransition.None),
Pagination.Selected.Value = "6",
Navigate(scrAddNomProposer, ScreenTransition.None),
Pagination.Selected.Value = "7",
Navigate(scrAddNomValidation, ScreenTransition.None),
Pagination.Selected.Value = "8",
Navigate(scrAddNomAttachments, ScreenTransition.None)
)

In addition, I also agree with @RandyHayes 's thought almost. You could also consider take a try to achieve your needs using Switch function. Please take a try with the following formula:

Switch(
           Pagination.Selected.Value,
           "1", Navigate(scrAddNomCore, ScreenTransition.None),
           "2", Navigate(scrAddNomKeyInfo, ScreenTransition.None),
           "3", Navigate(scrAddNomDetails, ScreenTransition.None),
           ...
           "8", Navigate(scrAddNomAttachments, ScreenTransition.None)
)

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.