Skip to content

Commit

Permalink
Reword
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Jan 21, 2025
1 parent c0daee9 commit 53b7a44
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion components/console/helpers/questionhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ but ``red`` could be set instead (could be more explicit)::
$question = new ChoiceQuestion(
'Please select your favorite color (defaults to red)',
// choices can also be PHP objects that implement __toString() method
['red', 'blue', 'yellow'], // pass an associative array to display custom indices: [3 => 'red', 7 => 'blue']
['red', 'blue', 'yellow'],
0
);
$question->setErrorMessage('Color %s is invalid.');
Expand All @@ -145,6 +145,28 @@ The option which should be selected by default is provided with the third
argument of the constructor. The default is ``null``, which means that no
option is the default one.

Choice questions display both the choice value and a numeric index, which starts
from 0 by default. The user can type either the numeric index or the choice value
to make a selection:

.. code-block:: terminal
Please select your favorite color (defaults to red):
[0] red
[1] blue
[2] yellow
>
.. tip::

To use custom indices, pass an array with custom numeric keys as the choice
values::

new ChoiceQuestion('Select a room:', [
102 => 'Room Foo',
213 => 'Room Bar',
]);

If the user enters an invalid string, an error message is shown and the user
is asked to provide the answer another time, until they enter a valid string
or reach the maximum number of attempts. The default value for the maximum number
Expand Down

0 comments on commit 53b7a44

Please sign in to comment.