PDA

View Full Version : Edittext onclick event


laszfellow
01-24-2007, 06:33 AM
I can't seem to get edittext to catch onclick event.
I am able to get it to catch on keydown/up event.

I wish to have an edittext box, that initially says in grey font,
"Please enter your name here".
So that when user clicks on edittext box, cleartext() would clear away the text.


<class name="DataEntryWindow" extends="windowpanel">
<attribute name="ClickedAlreadyLa" type="boolean" value="false"/>
<edittext name="DataText" text="Enter your name here, dear.">
<handler name="onkeydown" args="key">
<![CDATA[
if(key==13 && getValue().length > 0)
canvas.httpSend("userName", getValue());
]]>
</handler>
<handler name="onclick">
Debug.write(this+"What should I do to make you catch me?");
if(!ClickedAlreadyLa)
{
setAttribute("ClickedAlreadyLa", true);
clearText();
}
</handler>
<method name="init">
super.init();
setMaxlength(width/fontsize);
</edittext>
</class>


onkeydown is caught but not onclick. The debug never gets written.

Question:
Does edittext get to catch onclick or is onclick never passed on to edittext?
Or, should I check if any parent has caught onclick but not passed it on?

Also, setMaxlength() does not work. Is it because I am using an older version of laszlo server? Would there be an older version of laszlo in which setMaxlength is not allowed in edittext?

trucker_
01-24-2007, 06:52 AM
your code is wrong:

<method name="init">
super.init();
setMaxlength(width/fontsize);
</method>

and if you want to change the text when the user click the control, better use the onfocus event handler to do that:


<handler name="onfocus">
this.clearText();
</handler>

Hugo.

laszfellow
01-24-2007, 07:03 AM
On my system the code is correct, with the terminating </method> tag.
It just got left out when I copied the code from my Netbeans editor to forum editor and removed proprietary code.

Nevertheless, the following still won't work.

<method name="init">
super.init();
setMaxlength(width/fontsize);
</method>

tpatput
01-24-2007, 09:19 AM
I don't know Laszlo internals, so be careful with this suggestion... Your example worked for me when I moved super.init() after setting the maxlength.

setMaxlength() worked, with a warning that 'setMaxlength was undefined'. Would love to hear from a Laszlo guru why this is so.

setAttribute() worked without any warning.

in edittext.lzx, the init() method calls setMaxlength() on '_internalinputtext', so maybe the first call wins? the maxlength is null at that point.



<canvas height="500" width="500">
<class name="DataEntryWindow" extends="windowpanel">
<edittext name="DataText" text="Enter your name here, dear."
width="200">
<handler name="onfocus">
this.clearText();
</handler>
<method name="init">
setMaxlength(15); //worked with warning
//setAttribute('maxlength', 15); //worked without warning
super.init();
</method>
</edittext>
</class>
<DataEntryWindow/>
</canvas>


hope that helps.
Tom

senshi
01-26-2007, 07:12 AM
http://www.openlaszlo.org/jira/browse/LPP-3329

As a workaround:

<method name="init">
super.init();
this.maxlength = width / fontsize;
this.field.setMaxLength( this.maxlength );
</method>