From eebf3f12d559cd846d3787d10945671cf5d4d638 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 2 Feb 2014 01:15:45 +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/branches/WX_3_0_BRANCH@75768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/common/valtext.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index d8ae058900..0ab05c0ac3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -595,6 +595,7 @@ All (GUI): all commands without saving (Neil Chittenden). - Fix crash when Destroy()-ing a TLW with non-TLW parent. - Fix crash in wxAuiToolBar::GetToolBarFits(). +- Make wxFILTER_INCLUDE_LIST in wxTextValidator actually usable. - Make wxHTML more efficient when displaying large tables (Kinaou Hervé). - Prevent wxGrid rows/columns from becoming too small on double click. 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");