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.

inside custom component

Native Development

Reply
Highlighted
Contributor
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook
My Carrier: Telus

text not updating and will not refresh - help please

Hello All,

 

Can someone explain to me, why this wil not work 

 

1. Is there a signal other than onCreationCompleted that would cause a refresh by re-running function

2. My string val2 -- do not update in the text -- nothing is there?

 

import bb.cascades 1.0

Page {
    id: one_page  

 
    property alias one_page: one_page


    property alias t1: input_bird.hintText
    property alias t2: input_eggs.hintText

 

    property string val1
    property string val2

    // Function to set variables
    function setVariables (a, b) {

        if ((a == "0") && (b == "0")) {
            t1 = "12 eggs";
            t2 = "2 chickens";          
            val1 = "eggs";
            val2 = "chickens";
         } else if ((a == "0") && (b == "1")) {
            t1 = "12 eggs";
            t2 = "5 ostrich";
            val1 = "eggs";
            val2 = "ostrich";
         }
     }       
        
    Container {
        id: birds
                                      
        layout: StackLayout {
        }
        
        // Label Container
        Container {
            id: sac_label
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Top
            preferredWidth: 768
            preferredHeight: 150
                
            Label {
                text: "Birds to Eggs"
                horizontalAlignment: HorizontalAlignment.Center
                translationY: 20.0
            }
        }

         // Variables come from main.qml set by settings - getValueFrom, setValueFrom
        onCreationCompleted: { one_page.setVariables(mainTab.mV, mainTab.wV); }        
        
        // Start of Containers for Data Entry
        Container {
            id: bird_type
            translationY: 30
            horizontalAlignment: HorizontalAlignment.Center
            preferredWidth: 700
            preferredHeight: 90
            
            layout: DockLayout {
            }
                
            Label {
                text: "Type of Bird"
                translationY: 28.0
                translationX: 30.0
            }
            
            Container {
                id: bird_input
                horizontalAlignment: HorizontalAlignment.Right
                preferredHeight: 70
                topPadding: 2
                rightPadding: 5
                
                TextField {
                    id: Input_bird
                    preferredWidth: 225
                    translationY: 8
                    input {
                        submitKey: SubmitKey.Next
                        onSubmitted: {
                            text = qsTr("%1 %2").arg(CalcFunctions.numericOnly(text)).arg(val1);
                        }
                    }

                }

            }
        }

        Container {
            id: number_eggs
            translationY: 30
            horizontalAlignment: HorizontalAlignment.Center
            preferredWidth: 700
            preferredHeight: 90
            
            layout: DockLayout {
            }
            
            Label {
                text: "Number of Eggs"
                translationY: 28
                translationX: 30
            }

            Container {
                id: egg_input
                horizontalAlignment: HorizontalAlignment.Right
                preferredHeight: 70
                topPadding: 2
                rightPadding: 5
                
                TextField {
                    id: input_eggs
                    preferredWidth: 225
                    translationY: 8
                    input {
                        submitKey: SubmitKey.Done
                        onSubmitted: {
                            text = qsTr("%1 %2").arg(CalcFunctions.numericOnly(text)).arg(val2);
                            }
                        }
                    }
                }
            }
        }
        
        Container {
            id: linked
            translationY: 80
            horizontalAlignment: HorizontalAlignment.Center
            preferredWidth: 700
            preferredHeight: 125
       
            layout: DockLayout {
            }
            
            Label {
                text: "Sentence"
                verticalAlignment: VerticalAlignment.Center
                translationX: 30
            }
            
            Label {
                text: qsTr("(%1/%2)").arg(val1).arg(val2)
                verticalAlignment: VerticalAlignment.Center
                translationX: 200
                translationY: 5
            }

           Container {
                id: answer_out
                horizontalAlignment: HorizontalAlignment.Right
                verticalAlignment: VerticalAlignment.Center
                preferredHeight: 70
                translationY: 10
                rightPadding: 5
                
                TextField {
                    id: textOutput
                    preferredWidth: 225
                    hintText: qsTr("%1 %2 are layed by %3 %4").arg(input_eggs.text).arg(val2).arg(input_bird.text).arg(val1);

                   enabled: false
                }
            }           
        }
    }
}

Thanks.