Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » LineEdit, EditFields, DocEdit » [FEATURE] WhenLostFocus in EditField
[FEATURE] WhenLostFocus in EditField [message #30877] Thu, 27 January 2011 14:16 Go to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello all

When filling fields, I would like to check if the value is valid not when keying letters but just when losing the focus.

To avoid subclassing to use virtual LostFocus(), would it be possible to have a WhenLostFocus in EditField?. Or, is there any other way to validate the value of a field?


Best regards
Iñaki
Re: [FEATURE] WhenLostFocus in EditField [message #30892 is a reply to message #30877] Thu, 27 January 2011 21:07 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 671
Registered: November 2008
Location: France
Contributor
Hi Koldo,

I think this subject has already been discussed the answers were that you have to to derive the class.
But I completely agree with you. This situation is kind of common so adding WhenFocusLost would be a good thing from my point of view.

So +1

Re: [FEATURE] WhenLostFocus in EditField [message #30894 is a reply to message #30892] Thu, 27 January 2011 21:51 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello Didier

That is it. And the problem is that I would have to subclass DropTime, EditString, EditInt and others just to say the least Sad.

As all of them are a subclass of EditField, adding the callback there would solve it all.


Best regards
Iñaki
Re: [FEATURE] WhenLostFocus in EditField [message #30955 is a reply to message #30877] Sat, 29 January 2011 20:40 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13442
Registered: November 2005
Ultimate Member
koldo wrote on Thu, 27 January 2011 08:16

Hello all

When filling fields, I would like to check if the value is valid not when keying letters but just when losing the focus.

To avoid subclassing to use virtual LostFocus(), would it be possible to have a WhenLostFocus in EditField?. Or, is there any other way to validate the value of a field?


There are also quite hand virtuals ChildLostFocus/ChildGotFocus which IME in most cases cover this issue quite well.
Re: [FEATURE] WhenLostFocus in EditField [message #30967 is a reply to message #30955] Sun, 30 January 2011 16:49 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
mirek wrote on Sat, 29 January 2011 20:40

koldo wrote on Thu, 27 January 2011 08:16

Hello all

When filling fields, I would like to check if the value is valid not when keying letters but just when losing the focus.

To avoid subclassing to use virtual LostFocus(), would it be possible to have a WhenLostFocus in EditField?. Or, is there any other way to validate the value of a field?


There are also quite hand virtuals ChildLostFocus/ChildGotFocus which IME in most cases cover this issue quite well.


Thank you Mirek

For now is valid for me (in fact I used the same checking function for all field changes).

Perhaps in the future something could be included Rolling Eyes


Best regards
Iñaki
Re: [FEATURE] WhenLostFocus in EditField [message #31138 is a reply to message #30967] Wed, 09 February 2011 10:55 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 936
Registered: July 2009
Location: Germany
Experienced Contributor
Check out WithEnterAction in bazaar...
it's got that.., well almost. it invokes the WhenAction on LostFocus and when EnterKey is pressed.

u simply specify WithEnterAction<EditInt> instead of EditInt..

maybe that helps
Re: [FEATURE] WhenLostFocus in EditField [message #31140 is a reply to message #31138] Wed, 09 February 2011 12:44 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello Kohait00

Yes, although it is a pity to use a new class and losing .usc representation for layout file (or having to create a new that is really a copy of EditString, EditInt, and so on...) Sad

For EditFields and Enter I use the WhenEnter callback. This way WhenAction works always the same.


Best regards
Iñaki
Re: [FEATURE] WhenLostFocus in EditField [message #31141 is a reply to message #31140] Wed, 09 February 2011 14:07 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1781
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

koldo wrote on Wed, 09 February 2011 12:44

Yes, although it is a pity to use a new class and losing .usc representation for layout file (or having to create a new that is really a copy of EditString, EditInt, and so on...) Sad

Usc supports templates, so you don't have to lose anything Wink Example can be found in CtrlLib.usc, look for WithDropChoice.

Anyway, I agree that it is unnecessary in this case and that it is much more elegant to use WhenEnter and ChildLostFocus (which is great idea which never occured to me before Mirek mentioned it Smile ).

Honza
Re: [FEATURE] WhenLostFocus in EditField [message #31143 is a reply to message #31141] Wed, 09 February 2011 18:09 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello Honza

dolik.rce wrote on Wed, 09 February 2011 14:07

Usc supports templates, so you don't have to lose anything Wink Example can be found in CtrlLib.usc, look for WithDropChoice.

You can also create your new .usc with things like this:

ctrl MyEditStringLostFocus {
	>EditString;
}
ctrl MyEditIntLostFocus {
	>EditInt;
}
ctrl MyEditDoubleLostFocus {
	>EditDouble;
}
...

However this overcrowd layout menu unnecessarily with controls that are almost clone.

dolik.rce wrote on Wed, 09 February 2011 14:07

Anyway, I agree that it is unnecessary in this case and that it is much more elegant to use WhenEnter and ChildLostFocus (which is great idea which never occured to me before Mirek mentioned it Smile ).

Well, I agree. However it is possible that somebody would prefer something more detailed for a higher modularization degree. In addition, remember that specially when it is computationally expensive to check the values of all fields, with ChildLostFocus you do not know which field has lost the focus.


Best regards
Iñaki
Re: [FEATURE] WhenLostFocus in EditField [message #31250 is a reply to message #31143] Wed, 16 February 2011 18:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Hello Mirek

I am using ChildLostFocus() but it is called twice per click. Here I enclose you the functions called:

1st
LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
	Image Ctrl::DoMouse(int e, Point p, int zd)
		...
		void EditField::LeftDown(Point p, dword flags)
			bool Ctrl::SetFocus()
				bool Ctrl::SetFocus0(bool activate)
					void Ctrl::DoKillFocus(Ptr<Ctrl> pfocusCtrl, Ptr<Ctrl> nfocusCtrl)

2nd
LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
	void Ctrl::KillFocusWnd()
		void Ctrl::DoKillFocus(Ptr<Ctrl> pfocusCtrl, Ptr<Ctrl> nfocusCtrl)


Do you know what I am doing wrong?


Best regards
Iñaki
Re: [FEATURE] WhenLostFocus in EditField [message #31251 is a reply to message #31250] Wed, 16 February 2011 18:32 Go to previous message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Ouff, I see the problem

If this, no problem

	virtual void ChildLostFocus() {
		a = 27;
	}


but with an "Exclamation()" or other operation that changes the focus, this is required

	virtual void ChildLostFocus() {
		static bool inside;
		
		if (inside)
			return;
		
		inside = true;

		Exclamation("Lost focus");

		inside = false;
	}


The problem is that the Exclamation() gets the focus, so function is called twice:
- When the child looses the focus
- When the Exclamation() window gets it Smile


Best regards
Iñaki
Previous Topic: New Select form in DocEdit or LineEdit
Next Topic: TextCtrl (aka LineEdit,DocEdit) dont use global Style
Goto Forum:
  


Current Time: Sat Oct 23 15:20:26 CEST 2021

Total time taken to generate the page: 0.01771 seconds