Spring form:input for number
Asked Answered
A

3

9

I am using Spring's form:input as below :

<form:input type="number" .....>

in my jsp but when I check the html that is rendered on the browser it shows like :

type="number" type="text"

i.e., two type attributes are generated in the html.

On the other hand, if I check using inspect element option in the browser, it shows correct - only type="number" as expected.
Edit- My Question: Why am I getting two type attributes in generated html (type="number" type="text") ? How to get it resolved?

Announcer answered 26/11, 2014 at 4:39 Comment(1)
so what is your question ? doesnt work as expected ?Mclaurin
M
7

Spring form:input tag doesnt have any attribute named type and the type=number used in your code belongs to html5 input tag

Also have a look at HTML Text Input allow only Numeric input

Spring form tld lists the valid attributes of form:input element here

Mclaurin answered 26/11, 2014 at 6:31 Comment(3)
so does it mean that if I need to remove the extra "type" from my html then I have to use the html's <input type="" ...> instead of spring's form tag ?Announcer
yes you should , if you are going to use the UN-defined attribute to the tag it becomes meaningless isnt ?Mclaurin
I'm using spring form and I want to allow only numerics in the form:input, how can I do it?Mandler
S
1

HTML 5 with <!DOCTYPE html> has native solution:

<input type="number">

Beware that it does not behave in standard way in some browsers.

Try input type="number" to see the HTML5 version in action.

See also https://github.com/jonstipe/number-polyfill for transparent support in older browsers.

Substantiate answered 1/2, 2018 at 3:58 Comment(0)
T
1

I know this is old, but i found a solution that works just fine for me.

The spring:input form tag doesnt support the type attribute and there is no such thing as spring:number. But you can use jquery to add the type="number" attribute to the parsed html.

I used:

$(".selector").attr({
    "type" : "number",
});
Tournai answered 26/9, 2018 at 7:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.