How to clear textarea on click using AMD syntax

1907
8
Jump to solution
10-08-2013 06:53 AM
TracySchloss
Frequent Contributor
I have a textarea that starts out as
        <textarea data-dojo-type="dijit/form/Textarea" id="taAddress"/>Enter an Address, Place or ZIP.</textarea>


I'd like for the user to be able to click on the phrase "Enter an Address, Place or ZIP", and have that automatically empty the textarea so the user can just start typing without having to delete the phrase already in there.

I have a line which I've placed below my last function, but before the ending });
registry.byId("taAddress").on("click", clearTextInput('taAddress'));


and here's my function:
function clearTextInput (textFieldName) {     var txtarea = registry.byId(textFieldName);     txtarea.set("value", ""); }


My problem is that this fires as the page is loading, not on the map click.  I can see it starts out with my initial phrase, but then it clears itself, even before I have a chance to actually click in the textarea.
0 Kudos
1 Solution

Accepted Solutions
TracySchloss
Frequent Contributor
OK, this is what worked for me:
        <input id="taAddress" dojo-data-type="dijit/form/TextBox" placeHolder='Enter an Address, Place or ZIP' ></input>

View solution in original post

0 Kudos
8 Replies
BenFousek
Occasional Contributor III
Use the placeholder parameter. Works for all text widgets. No extra code required.

<input data-dojo-type="dijit/form/TextBox" data-dojo-props="placeholder: 'Search place or address'" />
0 Kudos
TracySchloss
Frequent Contributor
That sounded so promising, but no go.  I'm getting a type error on my registry.byId('taAddress'), saying it's undefined.  I have included "dijit/registry" and have another 'click' for a button right below this line that works just fine with registry.byId, so 'make sure you defined in' is not the issue.

Shouldn't registry.byId work for all digits and if it's an html element like 'div', that's when you'd use dom.byId instead?
0 Kudos
BenFousek
Occasional Contributor III
This doesn't work?

<textarea data-dojo-type="dijit/form/Textarea" data-dojo-props="placeholder: 'Enter an Address, Place or ZIP.'" id="taAddress"/></textarea>


I think you are getting the type error because you aren't wrapping in a function, but you don't need it with placeholder.

registry.byId("taAddress").on("click", function (evt) { clearTextInput('taAddress') });
0 Kudos
TracySchloss
Frequent Contributor
The string from the placeholder doesn't show up.
        <input id="taAddress" dojo-data-type="dijit/form/TextBox" dojo-data-props="placeholder: 'Enter an Address, Place or ZIP.'"></input>
0 Kudos
BenFousek
Occasional Contributor III
Hmmm... I've used placeholder forever and in every text widget. Never had a problem.

<input id="project-save-name" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, placeholder: 'Name', style: 'width:300px;'" />
0 Kudos
TracySchloss
Frequent Contributor
I changed it back to value=.  At least it shows the text I expect to see.  I still can't come up with a way to clear it out.  I'm getting confused about where I should define 'onClick'  Something I read said I shouldn't put any of any event code in the definition, it should all go outside in the form of registry.byId('mydijit').on('click', function); 

        <input id="taAddress" dojo-data-type="dijit/form/TextBox" value='Enter an Address, Place or ZIP' ></input>
0 Kudos
TracySchloss
Frequent Contributor
OK, this is what worked for me:
        <input id="taAddress" dojo-data-type="dijit/form/TextBox" placeHolder='Enter an Address, Place or ZIP' ></input>
0 Kudos
BenFousek
Occasional Contributor III
Great. Glad you got it working.
0 Kudos