wxIntegerValidator< T > how to use it? Topic is solved

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
okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

wxIntegerValidator< T > how to use it?

Post by okurtsev » Mon Jun 20, 2011 9:55 am

I've tried wxIntegerValidator and have a problem with it.

My edits box should let the user input integer values 4..20, but for example if I want to enter the value 20, I have to enter firstly the digit 2, which is impossible in the case, because the validator appears working on every char input.

Please advice something. Thanks.
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Mon Jun 20, 2011 11:24 am

wxIntegerValidator is a template class that you should instanciate with the type you want to validate.

So, imagine you want to validate a signed char integer, you can instanciate it like that :

Code: Select all

wxIntegerValidator<signed char> my_validator;
Once it is instanciated, you can use it as a wxNumValidator. So, if you only accept values between 1 and 10, you can simply perform this :

Code: Select all

my_validator.SetRange (1, 10);
This code uses C++ templates. If you are unfamiliar with this, I would highly suggest you to read about it before using it. You will find a lot of information about C++ templates on the web. All good C++ books should have a dedicated chapter on this subject too.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: wxIntegerValidator< T > how to use it?

Post by Auria » Mon Jun 20, 2011 12:42 pm

okurtsev wrote:I've tried wxIntegerValidator and have a problem with it.

My edits box should let the user input integer values 4..20, but for example if I want to enter the value 20, I have to enter firstly the digit 2, which is impossible in the case, because the validator appears working on every char input.

Please advice something. Thanks.
Validators might not be appropriate to do the entire verification in this case; as far as I know validators are more used to limit the characters that can be entered than to validate the final value.
So you can make the validator allow 1..20. And when the user clicks OK, presses enter, focuses another widget (as you wish), read the value from the text control, and validate it

Alternatively, you may want to use a spinner controls since, as far as I know, they have this particular feature built-in
"Keyboard not detected. Press F1 to continue"
-- Windows

okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

Re: wxIntegerValidator< T > how to use it?

Post by okurtsev » Mon Jun 20, 2011 3:12 pm

Auria wrote:
Validators might not be appropriate to do the entire verification in this case; as far as I know validators are more used to limit the characters that can be entered than to validate the final value.
Thank you for answer. It is a little bit strange, why the validators have such functionality like set limits (3..500), if they are only for limiting the input characters? What is the sense of setting such limits if nobody would be able to enter value 210, for example?

Does somebody know what is the most correct way in wxWidgets to implement the same functionality as with MFC validators? I mean checking the value on Update data and returning focus back if something went wrong?
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Mon Jun 20, 2011 5:30 pm

wxIntegerValidator seems to be very new, maybe the authors just didn't think about this use case :) if no one here knows, you can ask on the mailing list where you can reach the devs
"Keyboard not detected. Press F1 to continue"
-- Windows

okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

Re: wxIntegerValidator< T > how to use it?

Post by okurtsev » Fri Jun 24, 2011 7:39 am

Auria wrote:wxIntegerValidator seems to be very new, maybe the authors just didn't think about this use case :) if no one here knows, you can ask on the mailing list where you can reach the devs
Thank you for the help, seems it is really a little bit useless.
I would like to mark it "Solved" but don't know how with this new beautiful forum design.
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: wxIntegerValidator< T > how to use it?

Post by Auria » Fri Jun 24, 2011 3:39 pm

okurtsev wrote:
Auria wrote:wxIntegerValidator seems to be very new, maybe the authors just didn't think about this use case :) if no one here knows, you can ask on the mailing list where you can reach the devs
Thank you for the help, seems it is really a little bit useless.
I would like to mark it "Solved" but don't know how with this new beautiful forum design.
I think this functionality is not back yet ;)
"Keyboard not detected. Press F1 to continue"
-- Windows

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: wxIntegerValidator< T > how to use it?

Post by tierra » Fri Jun 24, 2011 3:57 pm

Auria wrote:
okurtsev wrote:I would like to mark it "Solved" but don't know how with this new beautiful forum design.
I think this functionality is not back yet ;)
It is, maybe I should change out the icon though. It's the tiny green checkbox icon in the top-right of the post to the left of the profile info.

okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

Re: wxIntegerValidator< T > how to use it?

Post by okurtsev » Fri Jun 24, 2011 4:20 pm

tierra wrote:It is, maybe I should change out the icon though. It's the tiny green checkbox icon in the top-right of the post to the left of the profile info.
OK, but the tiny green checkbox icon is absent in Chrome browser I always use. Had to run IE to mark it solved.
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: wxIntegerValidator< T > how to use it?

Post by Auria » Fri Jun 24, 2011 4:50 pm

tierra wrote:
Auria wrote:
okurtsev wrote:I would like to mark it "Solved" but don't know how with this new beautiful forum design.
I think this functionality is not back yet ;)
It is, maybe I should change out the icon though. It's the tiny green checkbox icon in the top-right of the post to the left of the profile info.
hmm well I don't see it, seems like the moderator ability to edit that was lost :)
"Keyboard not detected. Press F1 to continue"
-- Windows

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: wxIntegerValidator< T > how to use it?

Post by tierra » Fri Jun 24, 2011 5:12 pm

Auria wrote:
tierra wrote:It is, maybe I should change out the icon though. It's the tiny green checkbox icon in the top-right of the post to the left of the profile info.
hmm well I don't see it, seems like the moderator ability to edit that was lost :)
Someone found it (I'm guessing okurtsev did) since it's marked as solved now, and I didn't do it. This means that the green check button is now a red check button for those with permissions to mark the post as unsolved again.

I just tested out your permissions, and it does show up. :|

Post Reply