Expand my Community achievements bar.

Show/Hide rectangle depending on textfield content

Avatar

Level 3

Hello again!

I got my DropDown menu to change its color depending on the selected option ( http://forums.adobe.com/message/5156932#5156932 ) i thought that in a similar way I could make a TextField change its "background color" (actually i´m showing/hidden a red rectangle) depending on its content but is not.

If the TextField is empty we should see the background, as soon as the user enters content the background should be gone.

01.png

02.png

I have tthis code on the change event of the textbox:

if (xfa.event.newText != ""){

    RectangleRed.presence = "visible";

}else{

    RectangleRed.presence = "hidden";

}

But nothing happens, the red rectangle is always visible...

Any ideas?!

Thanks!

5 Replies

Avatar

Level 3

Y change the code to this:

if (xfa.event.newText == ""){

    RectangleRed.presence = "visible";

}else{

    RectangleRed.presence = "hidden";

}

and now is working but the rectangle dissapears when you get out of the textfield, I´d like it to be gone when you start typing something, is that possible?

Avatar

Level 10

Hi,

this should be possible this way:

RectangleRed.presence = xfa.event.fullText.length > 0 ? "invisible" : "visible";

Avatar

Level 3

Hi,

is the same as before, the red rectangle disappears when you get out of the text field, not while writig on it..

Avatar

Level 10

No, but I discovered a the reason why it looks like this.

Try to position the rectangle next to the text field. – You'll see it disappears immediately.

But if it is positioned behind the text field, the area for the text input is not updated immediatly, so it looks like the script doesn't work.

I don't see how to overcome this problem.

Avatar

Level 3

You are right! Neither I don´t know why this happens.