Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Check attribute value against the current value before setting it. Helps... #447

Open
wants to merge 1 commit into from

3 participants

caseycorcoran Michael Best Steven Sanderson
caseycorcoran

... in the case of iframe.url where resetting the value will refresh the iframe.

caseycorcoran caseycorcoran Check attribute value against the current value before setting it. He…
…lps in the case of iframe.url where resetting the value will refresh the iframe.
a4d3789
Michael Best
Collaborator

This is good, but also see #362. Probably the == and != should be === and !==.

caseycorcoran

Thanks Michael, I never took the time to look up strict equality operators... glad this issue led me to :)

Steven Sanderson

Strictly speaking this is a breaking change (someone might be relying on this behavior already to cause refreshes) so I'd give this a low priority and review it near the end of the 2.2 cycle if we still have capacity.

Michael Best
Collaborator

I agree we can wait on this. I'll set the waiting label.

caseycorcoran

Sure, I wrote a custom binding to get around it... so it's workable. You might want to add something to the documentation though. Thanks!

Michael Best
Collaborator

See #669 for more discussion on this topic.

Michael Best
Collaborator

Another counter argument to this change is shown in #1646. The value of an <option> element defaults to the text of that element, but setting the value overrides that behavior, even if the value you set is the same as the current text (and thus the current value).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 25, 2012
  1. caseycorcoran

    Check attribute value against the current value before setting it. He…

    caseycorcoran authored
    …lps in the case of iframe.url where resetting the value will refresh the iframe.
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 2 deletions.
  1. +3 −2 src/binding/defaultBindings.js
5 src/binding/defaultBindings.js
View
@@ -442,9 +442,10 @@ ko.bindingHandlers['attr'] = {
if (toRemove)
element.removeAttribute(attrName);
else
- element[attrName] = attrValue;
+ if( element[attrName] != attrValue ) element[attrName] = attrValue;
} else if (!toRemove) {
- element.setAttribute(attrName, attrValue.toString());
+ attrValue = attrValue.toString();
+ if( element.getAttribute(attrName) != attrValue ) element.setAttribute(attrName, attrValue);
}
}
}
Something went wrong with that request. Please try again.