ampersand-dom-bindings
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -79,2 +79,10 @@ var Store = require('key-tree-store'); | ||
}; | ||
} else if (type === 'value') { | ||
return function (el, value) { | ||
getMatches(el, selector).forEach(function (match) { | ||
if (!value && value !== 0) value = ''; | ||
match.value = value; | ||
}); | ||
previousValue = value; | ||
}; | ||
} else if (type === 'booleanClass') { | ||
@@ -81,0 +89,0 @@ // if there's a `no` case this is actually a switch |
{ | ||
"name": "ampersand-dom-bindings", | ||
"description": "Takes binding declarations and returns key-tree-store of functions that can be used to apply those bindings.", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "'Henrik Joreteg' <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -56,2 +56,13 @@ # ampersand-dom-bindings | ||
### value | ||
sets the value of the element to match value of the property. works well for `input`, `select`, and `textarea` elements. treats `undefined`, `null`, and `NaN` as `''` (empty string). | ||
```js | ||
'model.key': { | ||
type: 'value', | ||
selector: '#something', // or role | ||
} | ||
``` | ||
### booleanClass | ||
@@ -58,0 +69,0 @@ |
@@ -79,2 +79,35 @@ var test = require('tape'); | ||
test('value bindings', function (t) { | ||
var input = getEl('<input class="thing" type="text">'); | ||
var select = getEl('<select class="thing"><option value=""></option><option value="hello"></option><option value="string"></option></select>'); | ||
var textarea = getEl('<textarea class="thing"></textarea>'); | ||
[input, select, textarea].forEach(function (el) { | ||
var bindings = domBindings({ | ||
'model': { | ||
type: 'value', | ||
selector: '.thing' | ||
} | ||
}); | ||
t.equal(el.firstChild.value, ''); | ||
bindings.run('model', null, el, 'hello'); | ||
t.equal(el.firstChild.value, 'hello'); | ||
bindings.run('model', null, el, 'string'); | ||
t.equal(el.firstChild.value, 'string'); | ||
bindings.run('model', null, el, void 0); | ||
t.equal(el.firstChild.value, ''); | ||
bindings.run('model', null, el, null); | ||
t.equal(el.firstChild.value, ''); | ||
bindings.run('model', null, el, NaN); | ||
t.equal(el.firstChild.value, ''); | ||
}); | ||
t.end(); | ||
}); | ||
/* | ||
@@ -81,0 +114,0 @@ ### booleanClass |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17548
289
246
1