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

[Bug] Input checkbox value returns "on" in Internet Explorer 11 #15203

Closed
cspanring opened this issue May 3, 2017 · 12 comments
Closed

[Bug] Input checkbox value returns "on" in Internet Explorer 11 #15203

cspanring opened this issue May 3, 2017 · 12 comments

Comments

@cspanring
Copy link

Binding the value attribute of an input (checkbox) tag to a controller/component property seems broken in IE11.

See a minimal example here: https://cspanring.github.io/ie11-input-value/ (code)

template:

<input value={{inputValue}} type="checkbox" onclick={{action "getCheckboxValue"}}>My value is {{inputValue}}

controller:

inputValue: 3,

  actions: {
    getCheckboxValue() {
      let value = document.querySelector('input[type=checkbox]').value;
      // in IE11 value will be "on"
      alert('My value is: ' + value);
    },
  },
@Serabe
Copy link
Member

Serabe commented May 3, 2017

If you take Ember out of the equation, does it return 3?

@cspanring
Copy link
Author

Yes, if I set the value attribute in the template just to 3 IE11 will return it correctly.

Also, tried to replicate in vanilla javascript: http://output.jsbin.com/xutilididi/1/

If you have a few pointers or instincts where to start looking, I'm happy to take this on and try to triage it a little bit further.

@Serabe
Copy link
Member

Serabe commented May 3, 2017

Can confirm this. The problem is that value is not being set in the element at all. It can be checked looking at the element in the inspector panel.

@thirdwheel
Copy link

thirdwheel commented Jan 18, 2018

I stumbled on a solution for this. In IE11, if you set the value then change it to a checkbox, it will erase the value. So:

oCheckBox=document.createElement('input');
oCheckBox.name='testcheckbox';
oCheckBox.value='123456789';
oCheckBox.type='checkbox';
alert(oCheckBox.value);

This will show the correct value in Chrome, but will say 'on' in IE11. The following will ensure correct behaviour in both browsers:

oCheckBox=document.createElement('input');
oCheckBox.name='testcheckbox';
oCheckBox.type='checkbox';
oCheckBox.value='123456789';
alert(oCheckBox.value);

To quote someone in a chatroom when answering a hairy IE question, "did you properly light the incense? In which order did you chant and throw the chicken bones?" Instances like this make this question less silly the more insanity you find.

@thirdwheel
Copy link

thirdwheel commented Jan 19, 2018

Perhaps a more pertinent question - if you change the order of the value and type attributes, do you get the same behaviour?

EDIT: Here's a JSFiddle that shows what I mean: https://jsfiddle.net/0k20tjnL/

@aafaq-hassan-confiz
Copy link

I am having same issue in internet explorer 11. Yes, the problem is that value is not being set in the element at all. It is issue with any element whether it is checkbox or not. If a constant value is assigned then it is being set like "value=3", but value binding is not working at all like "value={{somevar}}". I am using ember-cli 3.1.4

@jherdman
Copy link
Contributor

Hey friends. I've worked around this in the past with radio buttons too (see #14712). The gist is that IE11 cares a lot about the order of your attributes. In general I've wrapped up native radio buttons in a component that has a didRender hook that looks like this:

  didRender() {
    // IE11 needs to have it value re-set
    this.element.value = this.value;
  },

@santanapaulo
Copy link

santanapaulo commented Aug 16, 2018

Any news on this? I am getting the same issue when I run tests in IE 11, which checks the values of my checkbox's.

image

@santanapaulo
Copy link

@jherdman Can you help me find a way to wrap up the native ember-radio-button?

@cspanring
Copy link
Author

@santanapaulo check out this PR/repo as an example: yapplabs/ember-radio-button#82

@christianhaller3000
Copy link

I stumbled on a solution for this. In IE11, if you set the value then change it to a checkbox, it will erase the value. So:

oCheckBox=document.createElement('input');
oCheckBox.name='testcheckbox';
oCheckBox.value='123456789';
oCheckBox.type='checkbox';
alert(oCheckBox.value);

This will show the correct value in Chrome, but will say 'on' in IE11. The following will ensure correct behaviour in both browsers:

oCheckBox=document.createElement('input');
oCheckBox.name='testcheckbox';
oCheckBox.type='checkbox';
oCheckBox.value='123456789';
alert(oCheckBox.value);

To quote someone in a chatroom when answering a hairy IE question, "did you properly light the incense? In which order did you chant and throw the chicken bones?" Instances like this make this question less silly the more insanity you find.

Thank you so much @thirdwheel
You saved my day!

@locks
Copy link
Contributor

locks commented Jul 22, 2023

Long live IE11 🙌

@locks locks closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants