wxTextEntryDialog - Is it possible to change validator text?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

wxTextEntryDialog - Is it possible to change validator text?

Post by apoorv569 »

I have a wxTextEntryDialog to take some input string from user, and I want it to not take empty strings, so I set a validator for it, here is the relevant code,

Code: Select all

    wxTextEntryDialog* favFolder;
    favFolder = new wxTextEntryDialog(this, "Enter folder name",
                                      "Add folder", wxEmptyString,
                                      wxTextEntryDialogStyle, wxDefaultPosition);

    favFolder->SetTextValidator(wxFILTER_EMPTY);
This works fine, and this other popup/dialog appears,
Image

I was wondering if it is possible to change this text "Required information entry is empty" to a custom message of my choice, "Folder name can't be empty, please enter a valid name" or something.?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextEntryDialog - Is it possible to change validator text?

Post by doublemax »

This is the original code:

Code: Select all

wxString wxTextValidator::IsValid(const wxString& str) const
{
    if ( HasFlag(wxFILTER_EMPTY) && str.empty() )
        return _("Required information entry is empty.");
    else if ( IsExcluded(str) )
        return wxString::Format(_("'%s' is one of the invalid strings"), str);
    else if ( !IsIncluded(str) )
        return wxString::Format(_("'%s' is not one of the valid strings"), str);

    // check the whole string for invalid chars.
    for ( wxString::const_iterator i = str.begin(), end = str.end();
          i != end; ++i )
    {
        if ( !IsValidChar(*i) )
        {
            return wxString::Format(
                _("'%s' contains invalid character(s)"), str);
        }
    }

    return wxString();
}
This means you can either:
1) if you use wxTranslation catalogs, provide a different translation for the text
2) subclass wxTextValidator and override this method
Use the source, Luke!
Post Reply