From 39edfa27a2859e69d0ec8185e2908ee68effce6f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 29 Dec 2013 00:01:43 +0000 Subject: [PATCH] Make wxFILTER_INCLUDE_LIST in wxTextValidator actually usable. Only check for its violation once the full text is entered as otherwise nothing could ever be entered when it was used. Closes #15778. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75449 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 ++++ src/common/valtext.cpp | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 805ba0a177..cbcc6b5012 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -14,3 +14,7 @@ All (GUI): - XRC handler for wxAuiToolBar added (Kinaou Hervé). - Add wxHtmlWindow::SetDefaultHTMLCursor() (Jeff A. Marr). - Add default ctor and Create() to wxContextHelpButton (Hanmac). + +wxMSW: + +- Make wxFILTER_INCLUDE_LIST in wxTextValidator actually usable. diff --git a/src/common/valtext.cpp b/src/common/valtext.cpp index e0621d050a..4a89f4f1e7 100644 --- a/src/common/valtext.cpp +++ b/src/common/valtext.cpp @@ -156,10 +156,15 @@ bool wxTextValidator::Validate(wxWindow *parent) wxString val(text->GetValue()); wxString errormsg; + + // We can only do some kinds of validation once the input is complete, so + // check for them here: if ( HasFlag(wxFILTER_EMPTY) && val.empty() ) - { errormsg = _("Required information entry is empty."); - } + else if ( HasFlag(wxFILTER_INCLUDE_LIST) && m_includes.Index(val) == wxNOT_FOUND ) + errormsg = wxString::Format(_("'%s' is invalid"), val); + else if ( HasFlag(wxFILTER_EXCLUDE_LIST) && m_excludes.Index(val) != wxNOT_FOUND ) + errormsg = wxString::Format(_("'%s' is invalid"), val); else if ( !(errormsg = IsValid(val)).empty() ) { // NB: this format string should always contain exactly one '%s' @@ -245,12 +250,8 @@ wxString wxTextValidator::IsValid(const wxString& val) const return _("'%s' should only contain digits."); if ( HasFlag(wxFILTER_NUMERIC) && !wxIsNumeric(val) ) return _("'%s' should be numeric."); - if ( HasFlag(wxFILTER_INCLUDE_LIST) && m_includes.Index(val) == wxNOT_FOUND ) - return _("'%s' is invalid"); if ( HasFlag(wxFILTER_INCLUDE_CHAR_LIST) && !ContainsOnlyIncludedCharacters(val) ) return _("'%s' is invalid"); - if ( HasFlag(wxFILTER_EXCLUDE_LIST) && m_excludes.Index(val) != wxNOT_FOUND ) - return _("'%s' is invalid"); if ( HasFlag(wxFILTER_EXCLUDE_CHAR_LIST) && ContainsExcludedCharacters(val) ) return _("'%s' is invalid");