Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Auto clear default text

Avatar

Former Community Member
I have searched all over to see how this is done. I found one other response to this question, but it was not complete.



Basically what I am wondering is, how do I set up my text field so that there is a default text to signify what the user should type into the box. When the user clicks the text field, this default is removed so they can begin typing.



Thank you!
1 Reply

Avatar

Level 5
It is easy...........

I would use the following code in "Enter" and "Exit" events....

Let us say the default text in the text field is "Default Text"



//Enter event JavaScript



var curText = this.rawValue;

var defText = "Default Text"



if (curText == defText) {

//when the current text is same as Default text clear the box

this.rawValu = "";

}

//no need of else condition as rest of the logic will be automatically taken care.

/////////////////////////////////////////////



//JS Code for Exit event



var defText = "Default Text";



if (this.isNull) {

this.rawValu = defText;

}

//again no need of else condition as rest of the logic will be automatically taken care.