techsjs2012
techsjs2012

Reputation: 1737

How to add html5 placeholder attribute to form input elements in Spring MVC

How to add html5 placeholder attribute to form input elements in Spring MVC?

Example:

<input type="text" required="true" name="firstName" id="firstName" placeholder="Your Name" 
                dojoType="dijit.form.ValidationTextBox" missingMessage="Ooops!  You forgot your first name!" />

Upvotes: 0

Views: 1397

Answers (2)

Derek Williams
Derek Williams

Reputation: 21

As far as I can tell dojo (1.9 checked) does not use html5 placeholders but creates a span to hold the placeholder text. The dojo documentation states:

Coming with Dojo 1.5 the HTML5 placeholder parameter (also known as a “hint”) has been implemented for all TextBox based widgets. Placeholder is gray example or hint text that the widget displays inside the input area of empty form fields, such as “John Doe” or “Your Name”. The text disappears when the user focuses the field.

This is inaccurate, the generated code has no html5 markup. I wish it did.

Upvotes: 0

mschr
mschr

Reputation: 8641

Use camelCasing the 'placeholder' into 'placeHolder'. Programmatic:

dojo.require("dijit.form.TextBox");
dojo.addOnLoad(function() {
    var inp = new dijit.form.TextBox({
        placeHolder: 'Your Name',
        name: 'firstName',
        id:'firstName'
    });
    dojo.byId('placeHolderNode').appendChild(inp.domNode);
});​

Declarative:

 <input type="text" required="true" name="firstName" id="firstName" 

       placeHolder="Your Name" 

            dojoType="dijit.form.ValidationTextBox" missingMessage="Ooops!  You forgot your first name!" />

Demo: http://jsfiddle.net/seeds/G6VYA/1

Upvotes: 1

Related Questions