Skip to content

Commit

Permalink
allow empty attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
pstadler committed Jul 24, 2014
1 parent 3393554 commit 78d19a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/tag.js
Expand Up @@ -14,8 +14,6 @@ var attrs = function attrs(a) {
var value = a[field];
if (typeof value === 'boolean') {
value = value ? field : null;
} else if (typeof value === 'string' && value.length === 0) {
value = null;
} else if (typeof value === 'number' && isNaN(value)) {
value = null;
}
Expand Down
1 change: 1 addition & 0 deletions test-browser.js
Expand Up @@ -5,6 +5,7 @@
// require('./test/test-form'); // disabled until server-specific tests are split out
require('./test/test-forms');
require('./test/test-render');
require('./test/test-tag');
// require('./test/test-validators'); // disabled until this unicode fix is merged: https://github.com/substack/testling/pull/35
require('./test/test-widgets');
}());
Expand Down
28 changes: 28 additions & 0 deletions test/test-tag.js
Expand Up @@ -2,6 +2,7 @@
'use strict';
var test = require('tape');
var tag = require('../lib/tag');
var forms = require('../');

test('generates a self-closing tag', function (t) {
var attrs = {
Expand All @@ -23,3 +24,30 @@ test('generates a non-self-closing tag', function (t) {
t.end();
});

test('allow empty attributes', function (t) {
var html = forms.widgets.select().toHTML('field', {
choices: {
'': 'Make a choice',
choice1: 'Choice 1',
choice2: 'Choice 2'
}
});
t.equal(html,
'<select name="field" id="id_field">' +
'<option value="">Make a choice</option>' +
'<option value="choice1">Choice 1</option>' +
'<option value="choice2">Choice 2</option>' +
'</select>'
);

var html = forms.widgets.text({
'data-empty': ''
}).toHTML('field');

t.equal(html,
'<input type="text" name="field" id="id_field" data-empty="" />'
);

t.end();
});

0 comments on commit 78d19a2

Please sign in to comment.