Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Contributor
defoo
Posts: 11
Registered: ‎02-22-2011
Accepted Solution

Sharing values between pages in NavigationPane

[ Edited ]

Hi,

 

I am trying out the NavigationPane with 2 pages. In the first page, I collects some values (via text fields, slider etc). After the user fills in all the values and click the "calculate" button, the second page will be pushed to the screen to display the results based on what the user entered before.

 

The way I am doing it right now is by storing the values from the "first" page into some global variables in a javascript file. The second page will then read from these variables and perform the necessary calculation.

 

First page:

import bb.cascades 1.0
import "ExtJS.js" as MortgageCal


NavigationPane {
    id: navPane
    Page {
        content: Container {
            id: mortgagePaymentSettingPage
            Container {
                TextField {
                    inputMode: TextFieldInputMode.PhoneNumber
                    id: valueTxt
                    onTextChanged: {
                        ExtJS.Value = Math.round(text)
                    }
                }
            }
        }
        actions: [
            ActionItem {
                title: "Calculate"
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered: {
                    navPane.deprecatedPushQmlByString("resultPage.qml");
                }
            }
        ]
    }
}

 

Second page:

import bb.cascades 1.0
import "ExtJS.js" as MortgageCal

Page {
    content: Container {
        id: ResultPage
        Container {
            Label {
                text: "User Entered: " + ExtJS.Value
            }
           
        }
    }
}

 

I am wondering if there is a better alternative to make the values from the first page "visiable" to the second page? 

 

 

Thanks,

Please use plain text.
Developer
raj_jyani
Posts: 100
Registered: ‎05-11-2011
My Carrier: AirTel

Re: Sharing values between pages in NavigationPane

[ Edited ]

Hi,

 

solution is very simple . You can access valueTxt.text property in resultPage.qml like same qml.

when you write valueTxt in second page and put a dot , it will not give suggetion , you have to write manually.

when you compile it will work completely .

You can only access first qml varibale when second page is pushed by navigation pane .

 

Try this,

 

main.qml

import bb.cascades 1.0

NavigationPane {
    id: navPane
    Page {
        content: Container {
            id: mortgagePaymentSettingPage
            Container {
                TextField {
                    inputMode: TextFieldInputMode.PhoneNumber
                    id: valueTxt
                }
            }
        }
        actions: [
            ActionItem {
                title: "Calculate"
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered: {
                    navPane.deprecatedPushQmlByString("resultPage.qml");
                }
            }
        ]
    }
}

 

resultPage.qml

 

import bb.cascades 1.0

Page {
    content: Container {
        Label {
            text: " I am First page Text : " + valueTxt.text
        }
    }
}

 

 

Please use plain text.
Contributor
defoo
Posts: 11
Registered: ‎02-22-2011

Re: Sharing values between pages in NavigationPane

Thanks! It works

Please use plain text.
Developer
soaman
Posts: 610
Registered: ‎03-03-2011
My Carrier: Mobitel

Re: Sharing values between pages in NavigationPane

OK, so IDs must be unique for whole app.
--------------------------------------------------------

Follow our developer blog on Slovenia BlackBerry Developer Group!
Please use plain text.
New Contributor
lawdawg123
Posts: 5
Registered: ‎12-11-2012
My Carrier: Att

Re: Sharing values between pages in NavigationPane

What if a page is pushed by navigationPane, and the variable is entered on the pushed page. Can that variable be seen by subsequent pushed pages?

In other words is there a way to make a variable available to all the pages in a stack no matter which page it is entered on?

 

 

 

 

Please use plain text.
New Contributor
lawdawg123
Posts: 5
Registered: ‎12-11-2012
My Carrier: Att

Re: Sharing values between pages in NavigationPane

I actually solved my own question.

 

On NavigationPane one can make a variable global by referencing Qt. In this case.

 

NavigationPane{
id:navPane
 Page{
    onCreationCompleted:{
    Qt.labelpage1=labelpage1;}
   Container{

   Label{
    id:labelpage1
     text:"Hello there"}...

 

//

labelpage1 can then be referenced on other pages as: 

 

Label{
  id:smileytongue:age2referencelabel
text:"Here is the entered text: " +Qt.labelpage1.text;
}

 

Please use plain text.