InputField, TextEntry, Password — Input field
InputField
( | string label , |
string
defaulttext
) ; |
TextEntry
( | string label , |
string
defaulttext
) ; |
Password
( | string label , |
string
defaulttext
) ; |
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. Bug compatibility mode: If used as TextEntry(), `opt(`hstretch) is automatically added (with a warning in the log about that fact) to avoid destroying dialogs written before fixing a geometry bug in the widget. The bug had caused all TextEntry widgets to be horizontally stretchable, so they consumed all the horizontal space they could get, typically making them as wide as the dialog. When used with the new name InputField(), they use a reasonable default width. You can still add `opt(`hstretch), of course. |
{ UI::OpenDialog( `VBox( `InputField("Name:"), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ // Build dialog with one input field field and an OK button. UI::OpenDialog( `VBox( `InputField(`id(`name), "Name:"), `PushButton("&OK") ) ); // Wait for user input. UI::UserInput(); // Get the input from the input field 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); y2warning( "Name: %1", name ); // 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 input field field and an OK button. UI::OpenDialog( `VBox( `InputField(`id(`name), "You will never see this:"), `PushButton("&OK") ) ); // Set an initial value for the input field field. UI::ChangeWidget(`id(`name), `Value, "Averell Dalton"); // Change the input field field's label. UI::ChangeWidget(`id(`name), `Label, "Name:"); // Wait for user input. UI::UserInput(); // Get the input from the input field 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 input field field, 4 Beatles buttons and an OK button. UI::OpenDialog( `VBox( `InputField(`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 input field field and an OK button. UI::OpenDialog( `VBox( `InputField(`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 input field 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 input field field and an OK button. UI::OpenDialog( `VBox( `InputField(`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 input field 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( `InputField( `id( `input ), "Input Field", "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(); }