Skip to content

Commit 61abc95

Browse files
committed
Updating description of the DialogHelper select method
1 parent 66c94e4 commit 61abc95

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

components/console/helpers/dialoghelper.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,30 @@ could use the ``ask`` method described above or, to make sure the user
160160
provided a correct answer, the ``askAndValidate`` method. Both have
161161
the disadvantage that you need to handle incorrect values yourself.
162162

163-
Instead, you can use the ``select`` method, which makes sure that the user
164-
can only enter a valid string from a predefined list::
163+
Instead, you can use the
164+
:method:`Symfony\\Component\\Console\\Helper\\DialogHelper::select`
165+
method, which makes sure that the user can only enter a valid string
166+
from a predefined list::
165167

166168
$dialog = $app->getHelperSet()->get('dialog');
167169
$colors = array('red', 'blue', 'yellow');
168170
169-
$color = $dialog->select($output, 'Please select your favorite color (default to red)', $colors, 0);
171+
$colorKey = $dialog->select($output, 'Please select your favorite color (default to red)', $colors, 0);
172+
$output->writeln('You have just selected: ' . $colors[$color]);
170173
171-
// Work with the color
174+
// ... do something with the color
172175
173176
If the user enters an invalid string, an error message is shown and the user
174177
is asked to provide the answer another time, till he enters a valid string.
175178

176-
The last parameter is the index of the default value in the array or ``null`` if
177-
no default should be provided.
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``)

0 commit comments

Comments
 (0)