[Closed] Changing edittext.text dynamically
Hey guys, I’m trying to do a small script to change a edittext box dynamically depending on what I select. Easy access to User Defined Attributes – but I can’t seem to change them, what ever I do, it won’t update. Any ideas how to do that?
here’s my script:
fn updateList = (
)
rollout ExposeUserDefined "Expose User Defined Attributes"
(
edittext userDef "User Defined:" text:"I want to change this dynamically" height:200 fieldWidth:200 labelOnTop:true
on ExposeUserDefined open do
(
callbacks.addScript #selectionSetChanged "updateList()" id:#Rollout_Update
)
on ExposeUserDefined close do
(
callbacks.removeScripts id:#Rollout_Update
)
on userDef entered txt do
(
setUserPropBuffer $ (userDef.text)
)
)
theNewFloater = newRolloutFloater "EUD" 300 220
addRollout ExposeUserDefined theNewFloater
While I wouldn’t do that exactly, your code actually works.
The only gotcha is that the User Props Buffer is updated when the text field loses focus.
This is because a multi-line edittext field does not call the on entered txt do handler when you press Enter but only when it goes out of focus. This is documented in the Help. With a HUGE WARNING box, just so nobody would miss it…
height:
If an explicit height: parameter is supplied on an editText item definition that specifies a pixel height greater than one line of text (18 pixels), that editText item becomes a multi-line edit box, allowing multiple lines of text to be entered.
WARNING!!!
If you specify the height of the edittext to be 18 pixels or more, the on entered event handler will not be called since the edittext will be in multi-line mode!
I felt that people could still miss that, so a bit later on the same page, it says
on <edittext> entered <arg> do <expr>
Called when the user enters text in the edit box and then presses ENTER or TAB to move the cursor out of the field. The <arg> argument will contain the new text in the edit box.
ONCE AGAIN, IN CASE YOU MISSED THE PREVIOUS WARNING:
If you specify the .height of the edittext to be 18 pixels or more, the on entered event handler will not be called since the edittext will be in multi-line mode!
Hehe thanks for pointing it out
The problem I have, is to update the edittext box depending on what I select. So, everytime I select a new item it will show a new user defined variables inside the edittext. As far as I can tell, edittext can’t be updated unless on run-time. Which is frustrating
global ExposeUserDefined
callbacks.removeScripts id:#Rollout_Update
rollout ExposeUserDefined "Expose User Defined Attributes"
(
edittext userDef "User Defined:" text:"I want to change this dynamically" height:200 fieldWidth:200 labelOnTop:true
fn updateList = (
if selection.count == 1 then
(
userDef.enabled = true
userDef.text = getUserPropBuffer $
)
else
(
userDef.text = if selection.count > 1 then "<multiple selected>" else "<none selected>"
userDef.enabled = false
)
)
on ExposeUserDefined open do
(
callbacks.addScript #selectionSetChanged "ExposeUserDefined.updateList()" id:#Rollout_Update
updateList()
)
on ExposeUserDefined close do
(
callbacks.removeScripts id:#Rollout_Update
)
on userDef entered txt do
(
if selection.count == 1 do
setUserPropBuffer $ (replace_LF_with_CRLF userDef.text) --fixed as DenisT suggested
)
)
try(closeRolloutFloater theNewFloater )catch()
theNewFloater = newRolloutFloater "EUD" 300 220
addRollout ExposeUserDefined theNewFloater
Thank you so much bobo I owe you one.
I see what you did there… You had to make the function updateList() locally to the rollout.
Again thanks:)
That is not for the case, but for the end of line (Carriage Return and Line Feed) conversion.
Denis is right, the actual buffer stores its values using CR and LF to separate the values, but the edit text would provide Line Feed only.
Your code works for writing arbitrary text into the buffer, but you probably want to change properties.
Also, what I did was just one way of solving the problem.
The alternative would have been to leave the function global, but pre-declare the rollout as global too before it so the function would “see” it. Then you would access the edittext as property of the global rollout.
Or you could prefix the access to the rollout and edittext control with :: to force search in global scope.
So there are at least 3 ways to do this. I just went with the most common one. It is the most compact because all references to rollout controls remain local and don’t require a prefix with a global variable. The only place that requires that in this case is the call from the callback.
I’ve got to ask denis – is what you’re smoking in yr avatar what i think it is you’re smoking?