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
Contributor
ThomasD
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook

TextField Signal Help

Hello,

 

I am having a few issues with updating the textfield.  Ideally my outcome would be for after the user inputs their numeric value and focus changes the measurement unit gets added.

 

For Example:

 

User Enters: 30  --> Final Value:  30 ft

 

Currently I am have this:

 

TextField {

      Id: input_val

 

      onTextChanging: {

                   input_val.text = Calc.numericOnly(text);

      }

      onTextChanged: {

                   textOuput.text = Calculate(input_val.text)

      }

}

 

I have tried changing:

 

      input_val.text = Calc.numericOnly(text);

 

to

 

      input_val.text = qsTr(“%1 %2”).arg(Calc.numericOnly(text)).arg(mainTab.mValue);

 

in onTextChanging.  All this has done is add the unit all of the time, even when there is no value in the text area.  You cannot get rid of it at this point, which is a tad annoying.  It of course also adds the unit after the user enters the first digit.  Ideally it would be nice to add once the textfield has lost focussed.  Therefore I tried adding:

 

      onFocusedChanged: {

                   input_val.text = qsTr(“%1 %2”).arg(Calc.numericOnly(text)).arg(mainTab.mValue);

      }

 

After OnTextChanging and nothing happens.  So I then moved tried to put:

 

      input_val.text = qsTr(“%1 %2”).arg(Calc.numericOnly(text)).arg(mainTab.mValue);

 

inside the OnTextChanged signal, which causes the program to crash.

 

Is there something really simple I am missing?  Any help would be very much appreciated.

 

Sincerely

D

Please use plain text.
Developer
dishooom
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810

Re: TextField Signal Help

Can you try if this one works?

 

    TextField {
                        id: txtFt
                        inputMode: TextFieldInputMode.NumbersAndPunctuation
                        onFocusedChanged: {
                            if(!focused)
                            {
                               txtFt.text = appendFt(txtFt.text);
                            }
                            else
                            {
                              txtFt.text = removeFt(txtFt.text);
                            }
                        }
                         function appendFt(txtVal)
                                {           
                                    if(txtVal.length > 0)                         
                                       return txtVal + "ft";
                                    else
                                       return txtVal;
                                    
                                }
                         function removeFt(txtVal)
                                {                                                                
                                    return txtVal.replace("ft", "");                                                                    
                                }
                    }

 - Dishooom

 

Hope this helps :Angel:

Please use plain text.