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
New Developer
Posts: 27
Registered: ‎01-04-2010
My Device: Not Specified
Accepted Solution

SystemPrompt result text string manipulation not working: what am I doing wrong?

I am trying to manipulate a 'string' I get from a SystemPrompt.  Here's my code:

SystemPrompt {
    id: prompt
    title: qsTr("prompt")
    inputField.maximumLength: 16
    inputField.defaultText: prompt
    inputField.emptyText: "prompt"
    inputField.inputMode: SystemUiInputMode.NumericKeypad
    // eNum: Default = 0, Email = 1, Password = 2, Phone = 3, Pin = 4,
	//       Url = 5, Symbols = 6, NumericKeypad = 7, NumbersAndPunctuation = 8
    onFinished: {
        if (result == SystemUiResult.ConfirmButtonSelection) {
            result = inputFieldTextEntry()
            //result = result.mid(0,4) + " " + result.mid(4,4) + " " + result.mid(8,4) + " " + result.mid(12,4)
			//result = inputFieldTextEntry.mid(0,4) + " " + inputFieldTextEntry.mid(4,4) + " " + inputFieldTextEntry.mid(8,4) + " " + inputFieldTextEntry.mid(12,4)
            labelPrompt.text = result
            //labelPrompt.text = result.mid(0,4) + " " + result.mid(4,4) + " " + result.mid(8,4) + " " + result.mid(12,4)
            toast.body = "prompt result: " + result
            //toast.body = "result: " + result+ result.size // this causes the toast result.size value to be "undefined"
            toast.show()
        } // if
    } // onFinished
} // SystemPrompt

[...]

attachedObjects: [
    SystemToast {
        id: toast
        onFinished: {
        }
    }
]

I have admittedly made the object names generic compared to my exact code.  My problem is this: none of the commented out code works.  What I'm trying to do is inject a space character between every 4 digits entered via the SystemPrompt.  If I enable any one of the commented lines, the app appears to break out of the onFinished IF without completing (evidenced by the lack of a toast).


I've tried type casting toString() here and there but that shouldn't be necessary since QML handles type casting automatically.  I even tried adding a string size debug value to my toast which yields an "undefined" result for result.size

 

Can someone point out the error of my ways here?

Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: SystemPrompt result text string manipulation not working: what am I doing wrong?

[ Edited ]

Hey there...

 

Just a few things...

1) Don't use result..  It's a read-only property, so you'll have to use another variable to hold your string...

2) You should be using Javascript, so instead of mid() use substr()...

3) and instead of size, use length...  myVar.length...

4) Use inputFieldTextEntry().substr() instead of inputFieldTextEntry.substr()

 

--Edit--

Don't forget the quotes around "prompt" for your defaultText: entry...

 

Oops... substr() and not substring()

New Developer
Posts: 27
Registered: ‎01-04-2010
My Device: Not Specified

Re: SystemPrompt result text string manipulation not working: what am I doing wrong?

[ Edited ]

First of all, a big thank you for your help.  Your idea to use jscript length instead of size works perfectly.  Thanks for the heads up on using "result" word for object name - I wasn't doing that but rather it was a poor choice when I genericized my code.  "prompt" in my example is a property string variable I'm carrying around and should have been "result" without quotes.  It gets set by this dialog and used as the default text so no quotes around it on purpose and it works.

 

I can't get the subst part to work.  Here's my code:

SystemPrompt {
    id: promptCardNumber
    title: qsTr("card number")
    inputField.maximumLength: 16
    inputField.defaultText: cardNumber
    inputField.emptyText: "enter your 16 digit card number"
    inputField.inputMode: SystemUiInputMode.NumericKeypad
    // Default = 0, Email = 1, Password = 2, Phone = 3, Pin = 4, Url = 5, Symbols = 6, NumericKeypad = 7, NumbersAndPunctuation = 8
    onFinished: {
        if (result == SystemUiResult.ConfirmButtonSelection) {
            cardNumberTemp = inputFieldTextEntry()
            cardNumber = cardNumberTemp.subst(0, 4) + " " + cardNumberTemp.subst(4, 4) + " " + cardNumberTemp.subst(8, 4) + " " + cardNumberTemp.subst(12, 4)
            labelCardNumber.text = cardNumber
            //toast.body = "card number: " + cardNumber
            toast.body = "card number: " + cardNumber + " " + cardNumber.length
            toast.show()
        } // if
    } // onFinished
} // SystemPrompt

In this real code sample, cardNumber is the string property that is changed by this prompt but used as the default text next time around.

 

This version doesn't show the toast at all.  I think the it's aborting out with the subst manipulation.  Any ideas?

Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: SystemPrompt result text string manipulation not working: what am I doing wrong?

[ Edited ]

Not subst... It's

 

cardNumber = cardNumberTemp.substr(0, 4) + " " +
             cardNumberTemp.substr(4, 4) + " " +
             cardNumberTemp.substr(8, 4) + " " +
             cardNumberTemp.substr(12, 4)

 

New Developer
Posts: 27
Registered: ‎01-04-2010
My Device: Not Specified

Re: SystemPrompt result text string manipulation not working: what am I doing wrong?

argh, I'm **bleep**.  Thanks so much!

New Developer
Posts: 27
Registered: ‎01-04-2010
My Device: Not Specified

Re: SystemPrompt result text string manipulation not working: what am I doing wrong?

... it so annoying that the IDE doesn't throw errors for something like using size() or subst() instead of substr()