Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display an Alert with Text Field Entry [duplicate]

How to display a text entry field in an alert to get input from the user and use that input back in the application (display the input on a label ) ?

As showing below enter image description here enter image description here

Thank you for your time.

like image 357
Assam AlZookery Avatar asked Jul 21 '16 14:07

Assam AlZookery


People also ask

How to show alert box with text field in jqueryui?

You can use JQueryUI Dialog to show a form in a dialog box. "I want to show a Alert Box with TextBox field in it,". alert box with text field is not possible at all.. (from what i have learnt till now).... u can use other jquery plugins like dialog to do the same..

How to add a textfield to the alert dialog?

In the “ actions ” property of alert dialog, we will place a FlatButton. When this button is tapped, the onPressed event will trigger and will store the value of the TextField in a String. Have a look at the code snippet below: If you run the code snippet above, the alert window will look like the one in the picture below.

What is the use of alert in HTML?

Definition and Usage. The alert() method displays an alert box with a specified message and an OK button. An alert box is often used if you want to make sure information comes through to the user. Note: The alert box takes the focus away from the current window, and forces the browser to read the message.

How to create alert dialog box in flutter?

Alert Dialog is a PopupBox will use to show small messages on Current widdow. This Alert Box can be of Warning/Info/Network alerts... Read about Alert Dialog with Close Button Flutter Read about Add Listview inside Dialog Box in flutter Let's Start Step 1:Create Flutter Application Step 2:Create TextFieldAlertDialog dart file and add below code


2 Answers

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Enter Text"
                                                                message:@"Enter some text below"
                                                         preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *submit = [UIAlertAction actionWithTitle:@"Submit" style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction * action) {

                                                   if (alert.textFields.count > 0) {

                                                       UITextField *textField = [alert.textFields firstObject];

                                                       textField.text // your text
                                                   }

                                               }];

[alert addAction:submit];

[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    textField.placeholder = @"something"; // if needs
}];

[self presentViewController:alert animated:YES completion:nil];
like image 184
Tommyizua Avatar answered Oct 04 '22 10:10

Tommyizua


To add TextField to UIAlertView set alertViewStyle property with UIAlertViewStylePlainTextInput

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
                                                message:@"Message"
                                               delegate:self
                                      cancelButtonTitle:@"Done"
                                      otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];

In .h file add UIAlertViewDelegate as a protocol and implement the delegate method alertView:clickedButtonAtIndex in the .m file.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"%@", [alertView textFieldAtIndex:0].text);
}
like image 30
Sunil Sharma Avatar answered Oct 04 '22 11:10

Sunil Sharma