Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX canary] Prevent unknown input types from erroring. #10690

Merged
merged 1 commit into from
Mar 21, 2015

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Mar 21, 2015

Browsers support various values for type, and generally auto-correct to just "text" if an unknown type is set via standard HTML.

Unfortunately, the same auto-correct behavior does not apply when setting the attribute directly, and in some circumstances throw an error where the type is not valid.

Specifically, the following throws an error in IE10:

var e = document.createElement('input');

e.type = 'search';

However the following HTML would auto-correct to "text":

<input type="search">

This PR adds a feature detect to see if a given type can be set to input. If setting the type results in the value, then we use it otherwise we default to "text".

Fixes #10458.

return type;
}

var input = document.createElement('input');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should likely just create this element once, not once per cache miss.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done.

@rwjblue rwjblue force-pushed the detect-input-type branch from 35cbe29 to 8d6b2f7 Compare March 21, 2015 15:26
Browsers support various values for `type`, and generally auto-correct
to just `"text"` if an unknown type is set via standard HTML.

Unfortunately, the same auto-correct behavior does not apply when
setting the attribute directly, and in some circumstances throw an
error where the type is not valid.

Specifically, the following throws an error in IE10:

```javascript
var e = document.createElement('input');

e.type = 'search';
```

However the following HTML would auto-correct to `"text"`:

```html
<input type="search">
```
@rwjblue rwjblue force-pushed the detect-input-type branch from 8d6b2f7 to 7526d1f Compare March 21, 2015 15:33
@stefanpenner
Copy link
Member

LGTM

mixonic added a commit that referenced this pull request Mar 21, 2015
[BUGFIX canary] Prevent unknown input types from erroring.
@mixonic mixonic merged commit 0b1a101 into emberjs:master Mar 21, 2015
@mixonic mixonic deleted the detect-input-type branch March 21, 2015 23:23
@mixonic
Copy link
Member

mixonic commented Mar 21, 2015

Thanks Robert.

@jayphelps
Copy link
Contributor

@rwjblue I think this can actually be pulled out if tildeio/htmlbars#355 lands and input#type is added to the list of bad pairs to use setAttribute instead? That way the HTML and attribute is still correctly set as the unknown type, but the property is text. c?

@rwjblue
Copy link
Member Author

rwjblue commented May 29, 2015

C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Internet Explorer + Ember 1.11 + {{input type="time"}} = Error: Invalid argument
4 participants