Validate on TextEditCtrl - Call on closed of GUi and not on lost focus - Normal behavior? - LOGGED
by elvince · in Torque 3D Professional · 03/26/2010 (9:07 am) · 7 replies
Hi,
In 1.1 Beta, I noticed that the validate call from an editCtrl is made only when my Gui is closed and not when I click on my button.
Is it the desired behavior?
By example, let take a gui where people are buying stuff. You have a quantity field that you don't want to be <1. When you click on Buy, you want to be sure that any value <1 are reset to 1.
I think the validate was called on lost focus during previous version and that's not the case on 1.1B or click on button do not take the focus (seems to be the case!)
Thanks,
In 1.1 Beta, I noticed that the validate call from an editCtrl is made only when my Gui is closed and not when I click on my button.
Is it the desired behavior?
By example, let take a gui where people are buying stuff. You have a quantity field that you don't want to be <1. When you click on Buy, you want to be sure that any value <1 are reset to 1.
I think the validate was called on lost focus during previous version and that's not the case on 1.1B or click on button do not take the focus (seems to be the case!)
Thanks,
About the author
Recent Threads
#2
On the same guicontrol, I set a editctrl & a button.
When I click on the button the editctrl keep the focus so the validate function is never called.
So I suspect that button do not take the focus when clicked.
As you said,if I press on "return", the control lose focus and the validate function is called.
My Gui code:
On the same topic, in my validate function if I set quantity to -10:
03/27/2010 (3:30 am)
Sorry if it was not clear.On the same guicontrol, I set a editctrl & a button.
When I click on the button the editctrl keep the focus so the validate function is never called.
So I suspect that button do not take the focus when clicked.
As you said,if I press on "return", the control lose focus and the validate function is called.
My Gui code:
new GuiWindowCtrl(npcInventory) {
text = "Trade with";
resizeWidth = "0";
resizeHeight = "0";
canMove = "1";
canClose = "1";
canMinimize = "0";
canMaximize = "0";
canCollapse = "0";
closeCommand = "ToggleWindowContainer(1,npcInventory);";
edgeSnap = "1";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "408 80";
extent = "376 432";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiWindowProfile";
visible = "0";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
new GuiButtonCtrl() {
text = "Buy";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "272 384";
extent = "96 32";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiButtonProfile";
visible = "1";
active = "1";
command = "npcInventory.buy();";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiTextEditCtrl(npcInventoryQuantity) {
validate = "npcInventory.ValidateQuantity();";
historySize = "0";
tabComplete = "0";
sinkAllKeyEvents = "0";
password = "0";
passwordMask = "*";
text = "1";
maxLength = "1024";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "320 352";
extent = "48 18";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiTextEditProfile";
visible = "1";
active = "1";
variable = "$Gui::npcInventoryQuantity";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiTextCtrl() {
text = "Quantity:";
...
};
};On the same topic, in my validate function if I set quantity to -10:
function npcInventory::ValidateQuantity(%this)
{
if($Gui::npcInventoryQuantity<1)
npcInventoryQuantity.text="1";
}it's working but not:function npcInventory::ValidateQuantity(%this)
{
if(npcInventoryQuantity.text<1)
npcInventoryQuantity.text="1";
}npcInventoryQuantity.text will not be updated ("evaluated" correctly) even if on the screen the value is correct.
#3
Correct. There are separate notions for "mouse focus" (mouse locking) and "keyboard focus" (first responder). A button press will make use of "mouse focus" (i.e. lock the mouse) but not of "keyboard focus" (become first responder).
To force validation from the button press, call GuiTextEditCtrl::forceValidateText() during your button event handling, i.e. in the buy() function you are calling.
03/27/2010 (7:22 am)
Quote:So I suspect that button do not take the focus when clicked.
Correct. There are separate notions for "mouse focus" (mouse locking) and "keyboard focus" (first responder). A button press will make use of "mouse focus" (i.e. lock the mouse) but not of "keyboard focus" (become first responder).
To force validation from the button press, call GuiTextEditCtrl::forceValidateText() during your button event handling, i.e. in the buy() function you are calling.
#4
Did something change on this? I'm pretty sure my Gui was working with previous version.
In all case, I know how to fix this.
What about:
03/27/2010 (8:50 am)
Thanks for the explanation, this was not easy to catch.Did something change on this? I'm pretty sure my Gui was working with previous version.
In all case, I know how to fix this.
What about:
Quote:npcInventoryQuantity.text will not be updated ("evaluated" correctly) even if on the screen the value is correct.
#5
Not that I'm aware of. This has been pretty much the same since TGE :)
There's been some recent changes to first responder handling but these only make the lose/gain first responder status handling more consistent and would only lead to the text edit controls seeing these signals more reliably.
Again, not sure I follow entirely (this my just be my state of mind today :)
Do you mean .text returns a different value than is displayed in the text edit ctrl on screen?
03/27/2010 (8:57 am)
Quote:Did something change on this?
Not that I'm aware of. This has been pretty much the same since TGE :)
There's been some recent changes to first responder handling but these only make the lose/gain first responder status handling more consistent and would only lead to the text edit controls seeing these signals more reliably.
Quote:npcInventoryQuantity.text will not be updated ("evaluated" correctly) even if on the screen the value is correct.
Again, not sure I follow entirely (this my just be my state of mind today :)
Do you mean .text returns a different value than is displayed in the text edit ctrl on screen?
#6
npcInventoryQuantity.text is different than the screen display
npcInventoryQuantity.text is different than my variable
my variable is the same as the display.
03/27/2010 (9:09 am)
yes exactlynpcInventoryQuantity.text is different than the screen display
npcInventoryQuantity.text is different than my variable
my variable is the same as the display.
#7
08/21/2010 (8:19 am)
Logged as TQA-869.
Associate Rene Damm
Not sure I follow entirely.
Which button do you refer to?
GuiTextEditCtrls trigger validation when they lose focus. If returnTab is set in the profile, losing focus will be forced when pressing enter.