@@ -168,22 +168,21 @@ from a predefined list::
168
168
$dialog = $app->getHelperSet()->get('dialog');
169
169
$colors = array('red', 'blue', 'yellow');
170
170
171
- $colorKey = $dialog->select($output, 'Please select your favorite color (default to red)', $colors, 0);
171
+ $color = $dialog->select(
172
+ $output,
173
+ 'Please select your favorite color (default to red)',
174
+ $colors,
175
+ 0
176
+ );
172
177
$output->writeln('You have just selected: ' . $colors[$color]);
173
178
174
179
// ... do something with the color
175
180
181
+ The option which should be selected by default is provided with the fourth
182
+ parameter. The default is ``null ``, which means that no option is the default one.
183
+
176
184
If the user enters an invalid string, an error message is shown and the user
177
- is asked to provide the answer another time, till he enters a valid string.
178
-
179
- The ``select `` method takes 6 parameters:
180
-
181
- * ``output ``: The output instance
182
- * ``question ``: The question to ask
183
- * ``choices ``: An array of strings with the choices the user can pick
184
- * ``default ``: The index of the default value in the array or ``null `` if no
185
- default should be provided (default ``null ``)
186
- * ``attempts ``: Maximum number of times to ask or ``false `` for infinite times
187
- (default ``false ``)
188
- * ``errorMessage ``: Error message to display when wrong answer is entered (default
189
- ``Value "%s" is invalid ``)
185
+ is asked to provide the answer another time, till he enters a valid string
186
+ or the maximum attempts is reached (which you can define in the fifth
187
+ parameter). The default value for the attempts is ``false ``, which means infinite
188
+ attempts. You can define your own error message in the sixth parameter.
0 commit comments