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
Regular Contributor
ametller
Posts: 54
Registered: ‎07-15-2010
My Device: Not Specified
Accepted Solution

How to get the text from a SystemPrompt (Cascades)

Hello,

 

I've been struggling with this for some hours now. I followed the "dialogs" example available at github, so I successfully created a SystemPrompt (the dialog that lets the user to enter text, and accept / dismiss it). Strangely enough, in that example there's no use of the user input text. Do you know how can I get that text in my QML? Here you have some sample code I'm using:

 

My QML:

// Default empty project template
import bb.cascades 1.0
import bb.system 1.0

// creates one page with a label
NavigationPane {
    id: navigationPane
	Page {
	    attachedObjects: [
            SystemPrompt {
	            id: prompt
	            title: qsTr("Enter a text for the label")
	            modality: SystemUiModality.Application
	            inputField.inputMode: SystemUiInputMode.Default
	            inputField.emptyText: "Label text..."
	            confirmButton.label: qsTr("Ok")
	            confirmButton.enabled: true
	            cancelButton.label: qsTr("Cancel")
	            cancelButton.enabled: true
	            onFinished: {
                    if (result == SystemUiResult.ConfirmButtonSelection) {
                        lab1.text = ????? // Here is where I don't know what to do
                    }
	            }
	        }
        ]
	                
	    Container {
	        layout: StackLayout {}
	        
	        Label {
                        id: lab1
text: "Label text" objectName: "lab1" textStyle.base: SystemDefaults.TextStyles.TitleText horizontalAlignment: HorizontalAlignment.Center } Button { text: "Update label" horizontalAlignment: HorizontalAlignment.Center topMargin: 150.0 onClicked: { //_appUi.editLabel(); prompt.show(); } } } } }

 Don't forget to add this in your app .cpp or .hpp file:

#include <bb/system/SystemCredentialsPrompt>
#include <bb/system/SystemDialog>
#include <bb/system/SystemPrompt>
#include <bb/system/SystemToast>
#include <bb/system/SystemUiButton>
#include <bb/system/SystemUiError>
#include <bb/system/SystemUiInputField>
#include <bb/system/SystemUiInputMode>
#include <bb/system/SystemUiPosition>
#include <bb/system/SystemUiResult>

 and also don't forget to include these in your app .cpp file (probably not all of them are needed but just in case I'm leaving them here for the moment):

qmlRegisterType<bb::system::SystemUiButton>("bb.system", 1, 0, "SystemUiButton");
	qmlRegisterType<bb::system::SystemUiInputField>("bb.system", 1, 0, "SystemUiInputField");
	qmlRegisterType<bb::system::SystemToast>("bb.system", 1, 0, "SystemToast");
	qmlRegisterType<bb::system::SystemPrompt>("bb.system", 1, 0, "SystemPrompt");
	qmlRegisterType<bb::system::SystemCredentialsPrompt>("bb.system", 1, 0, "SystemCredentialsPrompt");
	qmlRegisterType<bb::system::SystemDialog>("bb.system", 1, 0, "SystemDialog");
	qmlRegisterUncreatableType<bb::system::SystemUiError>("bb.system", 1, 0, "SystemUiError", "");
	qmlRegisterUncreatableType<bb::system::SystemUiResult>("bb.system", 1, 0, "SystemUiResult", "");
	qmlRegisterUncreatableType<bb::system::SystemUiPosition>("bb.system", 1, 0, "SystemUiPosition", "");
	qmlRegisterUncreatableType<bb::system::SystemUiInputMode>("bb.system", 1, 0, "SystemUiInputMode", "");
	qmlRegisterUncreatableType<bb::system::SystemUiModality>("bb.system", 1, 0, "SystemUiModality", "");
	qRegisterMetaType<bb::system::SystemUiResult::Type>("bb::system::SystemUiResult::Type");

 

Many thanks,

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: How to get the text from a SystemPrompt (Cascades)

If you scan ever so carefully through the docs, you'll stumble over https://developer.blackberry.com/cascades/reference/bb__system__systemprompt.html#inputfieldtextentr...

 

So replace your ????? with inputFieldTextEntry() and you'll get the text you need.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Regular Contributor
ametller
Posts: 54
Registered: ‎07-15-2010
My Device: Not Specified

Re: How to get the text from a SystemPrompt (Cascades)

Thanks Peter. I went a couple of times through the SystemPrompt documentation, but I didn't realize about this method. I think It's time to rest now... hehe

Please use plain text.
Eir
Contributor
Eir
Posts: 38
Registered: ‎11-28-2011
My Device: Z10

Re: How to get the text from a SystemPrompt (Cascades)

[ Edited ]

If you scan ever so carefully through the docs, you'll stumble over https://developer.blackberry.com/cascades/reference/bb__system__systemprompt.html#inputfieldtextentr...

 

Peter, what does the documentation say about working in C++? How do you retrieve the text value then?

http://eir3.com
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: How to get the text from a SystemPrompt (Cascades)


Eir wrote:
Peter, what does the documentation say about working in C++? How do you retrieve the text value then?

This should work the same in C++.  I don't generally use C++ so I can't advise further. Have you tried it?  If you did and it's not working, please post specifics (preferably in a new thread since this one is answered, so relatively few people would see your question if you just add it here).


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Eir
Contributor
Eir
Posts: 38
Registered: ‎11-28-2011
My Device: Z10

Re: How to get the text from a SystemPrompt (Cascades)

Thanks for the reply. I found my way through. I also don't use C++ regularly, thus I rely on the documentation, which in this case is incomplete, misleading and with errors in the code examples.

http://eir3.com
Please use plain text.
Contributor
gtirado
Posts: 13
Registered: ‎06-14-2011
My Device: -

Re: How to get the text from a SystemPrompt (Cascades)

Thank you very much for the reply! :smileyvery-happy:
Please use plain text.