Permalink
Browse files

Adding a "file" field, widget, example, and associated tests.

  • Loading branch information...
1 parent 298934e commit ea6dadcaadb42d4b02a839942e57625e3d10ca8e @ljharb ljharb committed Dec 19, 2012
Showing with 16 additions and 1 deletion.
  1. +2 −0 README.md
  2. +2 −1 example/complex.js
  3. +8 −0 lib/fields.js
  4. +1 −0 lib/widgets.js
  5. +2 −0 test/test-fields.js
  6. +1 −0 test/test-widgets.js
View
@@ -154,6 +154,7 @@ components following the same API.
* tel
* url
* date
+* file
### Widgets
@@ -172,6 +173,7 @@ components following the same API.
* multipleRadio
* multipleSelect
* label
+* file
### Validators
View
@@ -74,7 +74,8 @@ var form = forms.create({
nested_2: {
nested: fields.string()
}
- }
+ },
+ file: fields.file()
});
View
@@ -103,6 +103,14 @@ exports.string = function (opt) {
return f;
};
+exports.file = function (opt) {
+ if (!opt) { opt = {}; }
+ if (!opt.widget) { opt.widget = forms.widgets.file(opt.attrs || {}); }
+ var f = exports.string(opt);
+
+ return f;
+};
+
exports.number = function (opt) {
if (!opt) { opt = {}; }
var f = exports.string(opt);
View
@@ -54,6 +54,7 @@ exports.number = input('number');
exports.hidden = input('hidden');
exports.color = input('color');
exports.tel = input('tel');
+exports.file = input('file');
var passwordWidget = input('password');
var passwordFormatValue = function (value) { return null; };
View
@@ -165,6 +165,8 @@ var testField = function (field) {
testField('string');
+testField('file');
+
test('string parse', function (t) {
t.plan(5);
t.equal(stringField.parse(), '');
@@ -38,6 +38,7 @@ test('password', test_input('password'));
test('hidden', test_input('hidden'));
test('color', test_input('color'));
test('tel', test_input('tel'));
+test('file', test_input('file'));
test('date', function (t) {
var w = forms.widgets.date();

0 comments on commit ea6dadc

Please sign in to comment.