Jump to content

How to detect text has changed in a TextBox ?


aiaf
 Share

Go to solution Solved by GorzenDev,

Recommended Posts

text_field_name->Show();
choice_box_faction_label->Show();
choice_box_faction->Show();

db << "select count(name) from session where name = '" + text_field_name->GetText() + "';" >> user_registered;
if (user_registered == 1) {
	choice_box_faction->Disable();
}

I  disable a choice box if the user already exist.

My problem is that i want to enable the choice_box_faction in case the text_field_name is changed in any way.

Need an event (key down or widget selected).

Any idea ?

 

Hope i was clear with this description.

 

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

if (event.source == text_field_name) {
	if (initial_name != text_field_name->GetText()) {
		choice_box_faction->Enable();
	}
}

I input some text in  text_field_name.The event above only triggers on click , anywhere outside text box.

Looks like when focus was lost on the textbox.

So not exactly what i want , have to do one extra click to change the choice box.

 

Need an event when text was changed first time.

Any way to do this ? or maybe im missing some other way of doing

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

  • Solution

I'm not at my pc right now but from the top of my head I would say.

Open textfield.lua, scroll all the way down and add a widget event call to the keychar or keydown/up method.

You will find examples of calling an event inside any widget script.

I will add a proper example when I get home.

Link to comment
Share on other sites

we basicly posted at the same time :cool:

you could use different approaches.
either send a widget event whenevver any text is typed into the field by using "Option 1".
or send a widget event whenevver the "ENTER" key is pressed "Option 2". (assume the user is done typing)
or send an widget event whenevver the "TAB" key is pressed "Option 3". (assume the user wants to switch to the next element in case of a form that needs filling)
if a WidgetAction event interferes with other events you could always use WidgetSelect or WidgetMenu events

--OPTION 1--
function Script:KeyChar(charcode)
	local s = self.widget:GetText()
	local c = String:Chr(charcode)
	if c=="\b" then
		--Backspace
		if String:Length(s)>0 then
			if self.sellen==0 then
				if self.caretposition==String:Length(s) then
					s = String:Left(s,String:Length(s)-1)
				elseif self.caretposition>0 then
					s = String:Left(s,self.caretposition-1)..String:Right(s,String:Length(s)-self.caretposition)
				end
				self.caretposition = self.caretposition - 1
				self.caretposition = math.max(0,self.caretposition)
			else
				local c1 = math.min(self.caretposition,self.caretposition+self.sellen)
				local c2 = math.max(self.caretposition,self.caretposition+self.sellen)
				s = String:Left(s,c1)..String:Right(s,String:Length(s) - c2)
				self.caretposition = c1
				self.sellen = 0
			end
			self.widget:GetGUI():ResetCursorBlink()
			self.cursorblinkmode=true
			self.widget.text = s
			self.widget:Redraw()
		end
	elseif c~="\r" and c~="" then
		--Insert a new character
		local c1 = math.min(self.caretposition,self.caretposition+self.sellen)
		local c2 = math.max(self.caretposition,self.caretposition+self.sellen)
		s = String:Left(s,c1)..c..String:Right(s,String:Length(s) - c2)
		self.caretposition = self.caretposition + 1
		if self.sellen<0 then self.caretposition = self.caretposition + self.sellen end
		self.sellen=0
		self.widget:GetGUI():ResetCursorBlink()
		self.cursorblinkmode=true		
		self.widget.text = s
		self.widget:Redraw()
		--
		--OPTION 1--
		--send event with data = 999
		EventQueue:Emit(Event.WidgetAction,self.widget,999)
	end
end

function Script:KeyUp(keycode)
	if keycode==Key.Shift then
		self.shiftpressed=false
	end
	--
	if keycode==Key.Enter then
		self.widget:GetGUI():SetFocus(nil)
		--
		--OPTION 2--
		--send event with data = 997
		EventQueue:Emit(Event.WidgetAction,self.widget,997)
	elseif keycode==Key.Tab then
		self.widget:GetGUI():SetFocus(nil)
		--
		--OPTION 3--
		--send event with data = 998
		EventQueue:Emit(Event.WidgetAction,self.widget,998)
	end
end

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...