Macha
Macha

Reputation: 14654

input type ="url" for relative URLs

I had a input box for users to enter in a custom link to a page from the creation form (somewhat similar to Wordpress). (e.g. about/awards which gets used for http://site.com/pages/about/awards ) At some point, this stopped working in Chrome, as they now do stricter validation of input type="url" field. Which would be good but:

I've fixed it by just switching back to input type="text" but this defeats some of the useful stuff that type="url" added (such as the special keyboard on the iPhone).

Is this a part of the HTML5 spec, or a problem in Chrome's implementation?

Upvotes: 11

Views: 4987

Answers (5)

MiMFa
MiMFa

Reputation: 1164

My suggestion is to use a pattern for unallowed characters something like the following:

<input type="text" pattern="[^\<\>\^\`\{\|\}\r\n\t\f\v]*" placeholder="Your Relative or Absolute Path">

Enjoy...

Upvotes: 0

zara khaliq
zara khaliq

Reputation: 11

Some browsers do not allow validation to succeed when relative urls are entered. Instead set the input pattern attribute to a regular expression.

Upvotes: 1

Daniel Sokolowski
Daniel Sokolowski

Reputation: 12468

A plausable still semantic workaround that I am using is to allow relative URLs using the pattern attribute:

<input required="required" type="url" pattern="(https?|/).*?" name="sStyleBackgroundImageURL" value="{!sStyleBackgroundImageURL}"></input>

Upvotes: 2

Matthew Flaschen
Matthew Flaschen

Reputation: 284796

It says, "While the value of the element is not a valid absolute URL, the element is suffering from a type mismatch."

Upvotes: 2

GSto
GSto

Reputation: 42350

The spec is still being worked on, but from this quote, it sounds like it could be an issue with Chrome's implementation (bold emphasis is mine):

User agents may allow the user to set the value to a string that is not a valid absolute URL, but may also or instead automatically escape characters entered by the user so that the value is always a valid absolute URL (even if that isn't the actual value seen and edited by the user in the interface). User agents should allow the user to set the value to the empty string. User agents must not allow users to insert U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters into the value.

Source

Upvotes: 2

Related Questions