Comparing version 0.8.1 to 0.9.0
@@ -0,1 +1,5 @@ | ||
0.8.2 / 2014-07-30 | ||
================== | ||
* Add `hideError` option to disable automatic error rendering (#138) | ||
0.8.1 / 2014-07-24 | ||
@@ -2,0 +6,0 @@ ================== |
@@ -9,3 +9,3 @@ /*jslint node: true */ | ||
var wrappedContent = []; | ||
var errorHTML = field.errorHTML(); | ||
var errorHTML = opt.hideError ? '' : field.errorHTML(); | ||
if (field.widget.type === 'multipleCheckbox' || field.widget.type === 'multipleRadio') { | ||
@@ -52,8 +52,12 @@ var fieldsetAttrs = { classes: [] }; | ||
var tdContent = field.widget.toHTML(name, field); | ||
var errorHTML = field.errorHTML(); | ||
if (opt.errorAfterField) { | ||
tdContent += errorHTML; | ||
} else { | ||
tdContent = errorHTML + tdContent; | ||
if (!opt.hideError) { | ||
var errorHTML = field.errorHTML(); | ||
if (opt.errorAfterField) { | ||
tdContent += errorHTML; | ||
} else { | ||
tdContent = errorHTML + tdContent; | ||
} | ||
} | ||
var td = tag('td', {}, tdContent); | ||
@@ -60,0 +64,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"author": "Caolan McMahon", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -30,5 +30,6 @@ # Forms <sup>[![Version Badge][9]][8]</sup> | ||
* [ljharb](https://github.com/ljharb) | ||
* [ivanquirino](https://github.com/ivanquirino) | ||
* [richardngn](https://github.com/richardngn) | ||
* [caulagi](https://github.com/caulagi) | ||
* [luddep](http://github.com/luddep) | ||
* …and 27 more | ||
@@ -279,3 +280,4 @@ ## Example | ||
* cssClasses - A list of CSS classes for label and field wrapper | ||
* errorAfterField - if true, the error message will be displayed after the field, rather than before. | ||
* hideError - if true, errors won't be rendered automatically | ||
* errorAfterField - if true, the error message will be displayed after the field, rather than before | ||
* fieldsetClasses - for widgets with a fieldset (multipleRadio and multipleCheckbox), set classes for the fieldset | ||
@@ -282,0 +284,0 @@ * legendClasses - for widgets with a fieldset (multipleRadio and multipleCheckbox), set classes for the fieldset's legend |
@@ -49,3 +49,3 @@ /*jslint node: true */ | ||
test(tag + ' bound error', function (t) { | ||
t.plan(1); | ||
t.plan(4); | ||
var f = forms.create({ | ||
@@ -78,4 +78,43 @@ field_name: forms.fields.string({ | ||
); | ||
t.end(); | ||
}); | ||
// Error rendering disabled | ||
var f = forms.create({ | ||
field_name: forms.fields.string({ | ||
hideError: true, | ||
validators: [function (form, field, callback) { | ||
callback('validation error'); | ||
}] | ||
}), | ||
field_name_error_after: forms.fields.string({ | ||
hideError: true, | ||
errorAfterField: true, | ||
validators: [function (form, field, callback) { | ||
callback('validation error after field'); | ||
}] | ||
}) | ||
}); | ||
f.bind({field_name: 'val', field_name_error_after: 'foo'}).validate(function (err, f) { | ||
t.equal( | ||
f.toHTML(forms.render[tag]), | ||
'<' + tag + ' class="field error">' + | ||
'<label for="id_field_name">Field name</label>' + | ||
'<input type="text" name="field_name" id="id_field_name" value="val" />' + | ||
'</' + tag + '>' + | ||
'<' + tag + ' class="field error">' + | ||
'<label for="id_field_name_error_after">Field name error after</label>' + | ||
'<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />' + | ||
'</' + tag + '>' | ||
); | ||
t.equal(f.fields.field_name.errorHTML(), | ||
'<p class="error_msg">validation error</p>' | ||
); | ||
t.equal(f.fields.field_name_error_after.errorHTML(), | ||
'<p class="error_msg">validation error after field</p>' | ||
); | ||
}); | ||
t.end(); | ||
}); | ||
@@ -227,3 +266,3 @@ | ||
test('table bound error', function (t) { | ||
t.plan(1); | ||
t.plan(4); | ||
var f = forms.create({ | ||
@@ -260,5 +299,47 @@ field_name: forms.fields.string({ | ||
); | ||
t.end(); | ||
}); | ||
// Error rendering disabled | ||
var f = forms.create({ | ||
field_name: forms.fields.string({ | ||
hideError: true, | ||
validators: [function (form, field, callback) { | ||
callback('validation error'); | ||
}] | ||
}), | ||
field_name_error_after: forms.fields.string({ | ||
errorAfterField: true, | ||
hideError: true, | ||
validators: [function (form, field, callback) { | ||
callback('validation error after field'); | ||
}] | ||
}) | ||
}); | ||
f.bind({field_name: 'val', field_name_error_after: 'foo'}).validate(function (err, f) { | ||
t.equal( | ||
f.toHTML(forms.render.table), | ||
'<tr class="field error">' + | ||
'<th><label for="id_field_name">Field name</label></th>' + | ||
'<td>' + | ||
'<input type="text" name="field_name" id="id_field_name" value="val" />' + | ||
'</td>' + | ||
'</tr>' + | ||
'<tr class="field error">' + | ||
'<th><label for="id_field_name_error_after">Field name error after</label></th>' + | ||
'<td>' + | ||
'<input type="text" name="field_name_error_after" id="id_field_name_error_after" value="foo" />' + | ||
'</td>' + | ||
'</tr>' | ||
); | ||
t.equal(f.fields.field_name.errorHTML(), | ||
'<p class="error_msg">validation error</p>' | ||
); | ||
t.equal(f.fields.field_name_error_after.errorHTML(), | ||
'<p class="error_msg">validation error after field</p>' | ||
); | ||
}); | ||
t.end(); | ||
}); | ||
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
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
161825
3929
375