TextEntry, Password — Input field
TextEntry
( | string | label , |
string | defaulttext
) ; |
Password
( | string | label , |
string | defaulttext
) ; |
Value
the field's contents ( the user input )
Label
label above the field
ValidChars
valid input characters
InputMaxLength
limit the amount of characters
This widget is a one line text entry field with a label above it. An initial text can be provided.
![]() | Note |
---|---|
You can and should set a keyboard shortcut within the label. When the user presses the hotkey, the corresponding text entry widget will get the keyboard focus. |
{ UI::OpenDialog( `VBox( `TextEntry("Name:"), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ // Build dialog with one text entry field and an OK button. UI::OpenDialog( `VBox( `TextEntry(`id(`name), "Name:"), `PushButton("&OK") ) ); // Wait for user input. UI::UserInput(); // Get the input from the text entry field. // // Notice: The return value of UI::UserInput() does NOT return this value! // Rather, it returns the ID of the widget (normally the PushButton) // that caused UI::UserInput() to return. string name = (string) UI::QueryWidget(`id(`name), `Value); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Pop up a new dialog to echo the input. UI::OpenDialog( `VBox( `Label("You entered:"), `Label(name), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ // Build dialog with one text entry field and an OK button. UI::OpenDialog( `VBox( `TextEntry(`id(`name), "You will never see this:"), `PushButton("&OK") ) ); // Set an initial value for the text entry field. UI::ChangeWidget(`id(`name), `Value, "Averell Dalton"); // Change the text entry field's label. UI::ChangeWidget(`id(`name), `Label, "Name:"); // Wait for user input. UI::UserInput(); // Get the input from the text entry field. // // Notice: The return value of UI::UserInput() does NOT return this value! // Rather, it returns the ID of the widget (normally the PushButton) // that caused UI::UserInput() to return. string name = (string) UI::QueryWidget(`id(`name), `Value); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Pop up a new dialog to echo the input. UI::OpenDialog( `VBox( `Label("You entered:"), `Label(name), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ // Build dialog with one text entry field, 4 Beatles buttons and an OK button. UI::OpenDialog( `VBox( `TextEntry(`id(`name), "Name:"), `HBox( `PushButton(`id(`john), "&John" ), `PushButton(`id(`paul), "&Paul" ), `PushButton(`id(`george), "&George"), `PushButton(`id(`ringo), "&Ringo" )), `PushButton(`id(`ok), "&OK") ) ); // Wait for user input. any button = nil; // Input loop that only the OK button will leave. // The 4 Beatles buttons will just propose a name. repeat { button = UI::UserInput(); if ( button == `john ) UI::ChangeWidget(`id(`name), `Value, "John Lennon"); else if ( button == `paul ) UI::ChangeWidget(`id(`name), `Value, "Paul McCartney"); else if ( button == `george ) UI::ChangeWidget(`id(`name), `Value, "George Harrison"); else if ( button == `ringo ) UI::ChangeWidget(`id(`name), `Value, "Ringo Starr" ); } until ( button == `ok ); UI::CloseDialog(); }
{ // Build dialog with one text entry field and an OK button. UI::OpenDialog( `VBox( `TextEntry(`id(`hex_digits), "Hex number:"), `PushButton("&OK") ) ); UI::ChangeWidget(`id(`hex_digits), `ValidChars, "0123456789abcdefABCDEF" ); // Wait for user input. UI::UserInput(); // Get the input from the text entry field. // // Notice: The return value of UI::UserInput() does NOT return this value! // Rather, it returns the ID of the widget (normally the PushButton) // that caused UI::UserInput() to return. string name = (string) UI::QueryWidget(`id(`hex_digits), `Value); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Pop up a new dialog to echo the input. UI::OpenDialog( `VBox( `Label("You entered:"), `Label(name), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ // Build dialog with one text entry field and an OK button. UI::OpenDialog( `VBox( `TextEntry(`id(`hex_digits), "Hex number:"), `PushButton("&OK") ) ); UI::ChangeWidget(`id(`hex_digits), `ValidChars, "0123456789abcdefABCDEF" ); // Wait for user input. UI::UserInput(); // Get the input from the text entry field. // // Notice: The return value of UI::UserInput() does NOT return this value! // Rather, it returns the ID of the widget (normally the PushButton) // that caused UI::UserInput() to return. string name = (string) UI::QueryWidget(`id(`hex_digits), `Value); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Pop up a new dialog to echo the input. UI::OpenDialog( `VBox( `Label("You entered:"), `Label(name), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ // Build dialog with two password fields, an "OK" and a "Cancel" button. UI::OpenDialog( `VBox( `Password(`id(`pw1), "Enter password:"), `Password(`id(`pw2), "Confirm password:"), `HBox( `PushButton(`id(`ok), "&OK" ), `PushButton(`id(`cancel), "&Cancel") ) ) ); any button = nil; string pw1 = ""; string pw2 = ""; // Input loop. Will be terminated when the same password has been // entered in both fields or when 'Cancel' has been clicked. repeat { // Wait for Input. button = UI::UserInput(); // Get the values from both password fields. pw1 = (string) UI::QueryWidget(`id(`pw1), `Value ); pw2 = (string) UI::QueryWidget(`id(`pw2), `Value ); if ( button != `cancel ) { if ( pw1 == "" && pw2 == "" ) { // Error popup if nothing has been entered. UI::OpenDialog( `VBox( `Label("You must enter a password."), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } else if ( pw1 != pw2 ) { // Error popup if passwords differ. UI::OpenDialog( `VBox( `Label("The two passwords mismatch."), `Label("Please try again."), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } } } until ( ( pw1 != "" && pw1 == pw2 ) || button == `cancel ); UI::CloseDialog(); }
{ // Build dialog with two password fields, an "OK" and a "Cancel" button. UI::OpenDialog( `VBox( `Password(`id(`pw1), "Enter password:"), `Password(`id(`pw2), "Confirm password:"), `HBox( `PushButton(`id(`ok), "&OK" ), `PushButton(`id(`cancel), "&Cancel") ) ) ); any button = nil; string pw1 = ""; string pw2 = ""; // Input loop. Will be terminated when the same password has been // entered in both fields or when 'Cancel' has been clicked. repeat { // Wait for Input. button = UI::UserInput(); // Get the values from both password fields. pw1 = (string) UI::QueryWidget(`id(`pw1), `Value ); pw2 = (string) UI::QueryWidget(`id(`pw2), `Value ); if ( button != `cancel ) { if ( pw1 == "" && pw2 == "" ) { // Error popup if nothing has been entered. UI::OpenDialog( `VBox( `Label("You must enter a password."), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } else if ( pw1 != pw2 ) { // Error popup if passwords differ. UI::OpenDialog( `VBox( `Label("The two passwords mismatch."), `Label("Please try again."), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } } } until ( ( pw1 != "" && pw1 == pw2 ) || button == `cancel ); UI::CloseDialog(); }
{ UI::OpenDialog( `VBox( `TextEntry( `id( `input ), "Text entry", "pizza, pasta, pronta" ), `IntField( `id ( `field ), "Limit characters to...", -1, 100, -1 ), `PushButton( `id ( `butt ),"limit input" ), `PushButton( `id ( `exitButton ), "Exit" ) ) ); any ret = nil; ret = UI::UserInput(); while ( ret != `exitButton ) { integer chars = (integer) UI::QueryWidget(`id(`field), `Value); UI::ChangeWidget( `input, `InputMaxLength, chars ); ret = UI::UserInput(); } UI::CloseDialog(); }