Skip to content

Only first line of ValidationError message is displayed. #437

Open
@ryneeverett

Description

@ryneeverett

When the error message has multiple lines, only the first is displayed.

from prompt_toolkit.validation import Validator, ValidationError
from prompt_toolkit import prompt

class NumberValidator(Validator):
    def validate(self, document):
        text = document.text

        if text and not text.isdigit():
            i = 0

            # Get index of fist non numeric character.
            # We want to move the cursor here.
            for i, c in enumerate(text):
                if not c.isdigit():
                    break

            raise ValidationError(message='This input contains non-numeric characters.\nTHIS IS NOT DISPLAYED.',
                                  cursor_position=i)


number = int(prompt('Give a number: ', validator=NumberValidator()))
print('You said: %i' % number)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions