mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-10-07 14:54:00 +08:00
Relax checks on character entry in numeric validators
We can't perform the check for the invalid number in IsCharOk() because it's perfectly normal for the number to be temporarily invalid while it's being entered and, worse, sometimes this can't be avoided at all and the existing behaviour prevented the user from entering _anything_ into a control limited to the values between 10 and 20. See #23561. Closes #12968.
This commit is contained in:
+12
-10
@@ -255,19 +255,19 @@ wxIntegerValidatorBase::FromString(const wxString& s,
|
||||
}
|
||||
|
||||
bool
|
||||
wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
|
||||
wxIntegerValidatorBase::IsCharOk(const wxString& val,
|
||||
int WXUNUSED(pos),
|
||||
wxChar WXUNUSED(ch)) const
|
||||
{
|
||||
// We only accept digits here (remember that '-' is taken care of by the
|
||||
// base class already).
|
||||
if ( ch < '0' || ch > '9' )
|
||||
return false;
|
||||
|
||||
// And the value after insertion needs to be in the defined range.
|
||||
LongestValueType value;
|
||||
if ( !FromString(GetValueAfterInsertingChar(val, pos, ch), &value) )
|
||||
return false;
|
||||
|
||||
return IsInRange(value);
|
||||
// Accept anything that looks like a number here, notably do _not_ call
|
||||
// IsInRange() because this would prevent entering any digits in an
|
||||
// initially empty control limited to the values between "10" and "20".
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@@ -333,7 +333,8 @@ wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
|
||||
if ( ch < '0' || ch > '9' )
|
||||
return false;
|
||||
|
||||
// Check whether the value we'd obtain if we accepted this key is correct.
|
||||
// Check whether the value we'd obtain if we accepted this key passes some
|
||||
// basic checks.
|
||||
const wxString newval(GetValueAfterInsertingChar(val, pos, ch));
|
||||
|
||||
LongestValueType value;
|
||||
@@ -345,8 +346,9 @@ wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
|
||||
if ( posSep != wxString::npos && newval.length() - posSep - 1 > m_precision )
|
||||
return false;
|
||||
|
||||
// Finally check whether it is in the range.
|
||||
return IsInRange(value);
|
||||
// Note that we do _not_ check if it's in range here, see the comment in
|
||||
// wxIntegerValidatorBase::IsCharOk().
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // wxUSE_VALIDATORS && wxUSE_TEXTCTRL
|
||||
|
||||
Reference in New Issue
Block a user