Permalink
Browse files

range/numeric

  • Loading branch information...
1 parent 2371e3e commit 3787b181647cdebb106355bd7e3b289f1f2a0894 @searls committed Mar 2, 2012
View
22 dist/fill-all-the-things.js
@@ -56,10 +56,10 @@ site: https://searls.github.com/fill-all-the-things
}
}, {
test: function(it) {
- return it.is('[type="tel"]');
+ return it.is('[type="tel"]') || /phone/i.test(it.attr('name'));
},
action: function() {
- return "123-456-7890";
+ return "1234567890";
}
}, {
test: function(it) {
@@ -69,6 +69,13 @@ site: https://searls.github.com/fill-all-the-things
return "http://www.w3.org";
}
}, {
+ test: function(it) {
+ return it.is('[type="range"],.numeric,[max],[min]');
+ },
+ action: function(it) {
+ return it.attr('max') || it.attr('min') || "0";
+ }
+ }, {
test: function(it, val) {
return !val;
},
@@ -96,8 +103,15 @@ site: https://searls.github.com/fill-all-the-things
];
f.fill = function() {
var $inputs;
- return $inputs = $(':input:visible:enabled').val(function(i, val) {
- return doFirst(types, [$(this), val]);
+ return $inputs = $(':input:visible:enabled:not([readonly])').val(function(i, val) {
+ var _this = this;
+ return _(doFirst(types, [$(this), val])).tap(function(newVal) {
+ if (val !== newVal) {
+ return _.defer(function() {
+ return $(_this).trigger('change');
+ });
+ }
+ });
});
};
figureOutAValue = function(it, val) {
View
2 dist/fill-all-the-things.min.js
1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
8 index.html
@@ -51,6 +51,14 @@
<label for="maxlengthField">max length</label>
<input id="maxlengthField" maxlength="4" type="text"></input>
</div>
+ <div>
+ <label for="numericField">numeric</label>
+ <input id="numericField" class="numeric" type="text"></input>
+ </div>
+ <div>
+ <label for="rangeField">ranges</label>
+ <input id="rangeField" min="5" max="30" type="range"></input>
+ </div>
<hr/>
<div>
<input id="checkbox1" type="checkbox" value="true"></input>
View
30 spec/fill-all-the-things-spec.coffee
@@ -71,9 +71,33 @@
Given -> @$input = affix('input[type="url"]')
Yields -> @$input.val() is "http://www.w3.org"
- describe "password fields", ->
- Given -> @$input = affix('input[type="password"]')
- Yields -> @$input.val() == "f1llTh!NG$?"
+ describe "password fields", ->
+ Given -> @$input = affix('input[type="password"]')
+ Yields -> @$input.val() == "f1llTh!NG$?"
+
+ describe "numeric stuff", ->
+ context "has a .numeric class", ->
+ Given -> @$input = affix('input.numeric')
+ Yields -> isFinite(parseInt(@$input.val(),10))
+
+ context "is a range", ->
+ Given -> @$input = affix('input[type="range"]')
+ Yields -> parseInt(@$input.val(),10) is 0
+
+ context "has a min", ->
+ Given -> @$input = affix('input[min="5"]')
+ Yields -> @$input.val() == "5"
+
+ context "has a max", ->
+ Given -> @$input = affix('input[max="50"]')
+ Yields -> @$input.val() == "50"
+
+ context "has it all", ->
+ Given -> @$input = affix('input.numeric[min="10"][max="13"]')
+ Yields ->
+ n = parseInt(@$input.val(),10)
+ isFinite(n) and n >= 10 and n <= 13
+
describe "checkboxen", ->
Given -> @$input = affix('input[type="checkbox"]')
View
3 src/fill-all-the-things.coffee
@@ -35,6 +35,9 @@ f = window.FillAllTheThings ||= {}
test: (it) -> it.is('[type="url"]')
action: -> "http://www.w3.org"
,
+ test: (it) -> it.is('[type="range"],.numeric,[max],[min]')
+ action: (it) -> it.attr('max') or it.attr('min') or "0"
+ ,
test: (it, val) -> !val
action: -> "Filling a Thing"
,

0 comments on commit 3787b18

Please sign in to comment.