Skip to content

Commit

Permalink
Better type-based checking on old and new values
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Feb 24, 2017
1 parent e5c5b9e commit 2067e02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Renderer.js
Expand Up @@ -260,7 +260,11 @@
if (newValue == null || (element.type === 'number' && isNaN(newValue))) {
newValue = ''
}
if (element[this.name] != newValue) {
var oldValue = element[this.name]
if (typeof oldValue === 'string' && typeof newValue !== 'string') {
newValue = newValue == null ? '' : String(newValue)
}
if (oldValue != newValue) {
element[this.name] = newValue
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Element.js
Expand Up @@ -135,6 +135,12 @@ define([
})
assert.strictEqual(new Radio().type, 'radio')
},
numberInput0: function() {
var numberInput = new NumberInput(new Variable(0))
document.body.appendChild(numberInput)
assert.strictEqual(numberInput.type, 'number')
assert.strictEqual(numberInput.valueAsNumber, 0)
},
dateInput: function() {
var startingDate = new Date(1458345600000)
var dateVariable = new Variable(startingDate)
Expand Down

0 comments on commit 2067e02

Please sign in to comment.