diff --git a/.eslintrc b/.eslintrc index 790e965..20e5556 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,6 @@ "max-statements": [2, 19], "new-cap": [2, { "capIsNewExceptions": ["Template"] }], "no-extra-parens": [0], - "object-curly-spacing": [0, "always"], "operator-linebreak": [2, "after"] } } diff --git a/example/complex.js b/example/complex.js index f19971e..49b2dfa 100644 --- a/example/complex.js +++ b/example/complex.js @@ -27,9 +27,9 @@ var complexForm = forms.create({ name: fields.string({ required: validators.required('%s is required, silly!') }), - email: fields.email({required: true, label: 'Email Address'}), + email: fields.email({ required: true, label: 'Email Address' }), website: fields.url(), - password: fields.password({required: true}), + password: fields.password({ required: true }), password_confirm: fields.password({ required: true, validators: [validators.matchField('password')] @@ -58,19 +58,19 @@ var complexForm = forms.create({ ] }), more_options: fields.array({ - choices: {one: 'item 1', two: 'item 2', three: 'item 3'}, + choices: { one: 'item 1', two: 'item 2', three: 'item 3' }, widget: widgets.multipleCheckbox() }), even_more: fields.string({ - choices: {one: 'item 1', two: 'item 2', three: 'item 3'}, + choices: { one: 'item 1', two: 'item 2', three: 'item 3' }, widget: widgets.multipleRadio() }), and_more: fields.array({ - choices: {one: 'item 1', two: 'item 2', three: 'item 3'}, + choices: { one: 'item 1', two: 'item 2', three: 'item 3' }, widget: widgets.multipleSelect() }), notes: fields.string({ - widget: widgets.textarea({rows: 6}) + widget: widgets.textarea({ rows: 6 }) }), spam_me: fields['boolean'](), nested_1: { @@ -84,13 +84,13 @@ http.createServer(function (req, res) { complexForm.handle(req, { success: function (form) { var req_data = parse(req.url, 1).query; - res.writeHead(200, {'Content-Type': 'text/html'}); + res.writeHead(200, { 'Content-Type': 'text/html' }); res.write('
' + util.inspect(form.data) + ''); }, other: function (form) { - res.writeHead(200, {'Content-Type': 'text/html'}); + res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(template.expand({ form: form.toHTML(), method: 'POST', diff --git a/example/simple.js b/example/simple.js index 806b846..a847978 100644 --- a/example/simple.js +++ b/example/simple.js @@ -16,21 +16,21 @@ var template = jsontemplate.Template( // our example registration form var reg_form = forms.create({ - username: fields.string({required: true}), - password: fields.password({required: true}), + username: fields.string({ required: true }), + password: fields.password({ required: true }), confirm: fields.password({ required: true, validators: [validators.matchField('password')] }), personal: { - name: fields.string({required: true, label: 'Name'}), - email: fields.email({required: true, label: 'Email'}), + name: fields.string({ required: true, label: 'Name' }), + email: fields.email({ required: true, label: 'Email' }), address: { - address1: fields.string({required: true, label: 'Address 1'}), - address2: fields.string({label: 'Address 2'}), - city: fields.string({required: true, label: 'City'}), - state: fields.string({required: true, label: 'State'}), - zip: fields.number({required: true, label: 'ZIP'}) + address1: fields.string({ required: true, label: 'Address 1' }), + address2: fields.string({ label: 'Address 2' }), + city: fields.string({ required: true, label: 'City' }), + state: fields.string({ required: true, label: 'State' }), + zip: fields.number({ required: true, label: 'ZIP' }) } } }); @@ -38,13 +38,13 @@ var reg_form = forms.create({ http.createServer(function (req, res) { reg_form.handle(req, { success: function (form) { - res.writeHead(200, {'Content-Type': 'text/html'}); + res.writeHead(200, { 'Content-Type': 'text/html' }); res.write('
' + util.inspect(form.data) + ''); }, // perhaps also have error and empty events other: function (form) { - res.writeHead(200, {'Content-Type': 'text/html'}); + res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(template.expand({ form: form.toHTML(), enctype: '', diff --git a/lib/widgets.js b/lib/widgets.js index 15f4632..a22d7b0 100644 --- a/lib/widgets.js +++ b/lib/widgets.js @@ -171,7 +171,7 @@ exports.multipleCheckbox = function (options) { var inputHTML = tag('input', [attrs, userAttrs, w.attrs || {}]); // label element - var labelHTML = tag('label', {'for': id, classes: w.labelClasses}, f.choices[k]); + var labelHTML = tag('label', { 'for': id, classes: w.labelClasses }, f.choices[k]); return html + inputHTML + labelHTML; }, ''); @@ -219,7 +219,7 @@ exports.multipleRadio = function (options) { }; var inputHTML = tag('input', [attrs, userAttrs, w.attrs || {}]); // label element - var labelHTML = tag('label', {'for': id, classes: w.labelClasses}, f.choices[k]); + var labelHTML = tag('label', { 'for': id, classes: w.labelClasses }, f.choices[k]); return html + inputHTML + labelHTML; }, ''); diff --git a/test/test-fields.js b/test/test-fields.js index 340bc40..a9d0575 100644 --- a/test/test-fields.js +++ b/test/test-fields.js @@ -130,7 +130,7 @@ var testField = function (field) { test(field + ' validate required', function (t) { t.plan(5); - var f = fields[field]({required: true}); + var f = fields[field]({ required: true }); f.validators = []; f.bind(undefined).validate('form', function (err, fieldObject) { t.equal(fieldObject.value, undefined); @@ -290,7 +290,7 @@ test('email validators', function (t) { fields.email().validators[0].toString(), forms.validators.email().toString() ); - var f = fields.email({validators: [fn1, fn2]}); + var f = fields.email({ validators: [fn1, fn2] }); t.equal( f.validators[0].toString(), forms.validators.email().toString() @@ -350,7 +350,7 @@ test('url validators', function (t) { fields.url().validators[0].toString(), forms.validators.url().toString() ); - var f = fields.url({validators: [fn1, fn2]}); + var f = fields.url({ validators: [fn1, fn2] }); t.equal( f.validators[0].toString(), forms.validators.url().toString() @@ -382,7 +382,7 @@ test('date validators', function (t) { fields.date().validators[0].toString(), forms.validators.date().toString() ); - var f = fields.date({validators: [fn1, fn2]}); + var f = fields.date({ validators: [fn1, fn2] }); t.equal( f.validators[0].toString(), forms.validators.date().toString() diff --git a/test/test-form.js b/test/test-form.js index 65b1703..3877cf7 100644 --- a/test/test-form.js +++ b/test/test-form.js @@ -20,7 +20,7 @@ test('bind', function (t) { t.equal(form.isValid, undefined); // bound - var f = form.bind({field1: 'data one', field2: 'data two'}); + var f = form.bind({ field1: 'data one', field2: 'data two' }); t.equal(f.fields.field1.value, 'data one'); t.equal(f.fields.field1.data, 'data one'); t.equal(f.fields.field1.error, undefined); @@ -32,7 +32,7 @@ test('bind', function (t) { t.equal(f.bind, undefined); t.equal(f.handle, undefined); - t.deepEqual(f.data, {field1: 'data one', field2: 'data two'}); + t.deepEqual(f.data, { field1: 'data one', field2: 'data two' }); t.notEqual(form, f, 'bind returns new form object'); t.end(); @@ -48,7 +48,7 @@ test('bind with missing field in data keeps field in form', function (t) { t.equal(form.isValid, undefined); // bound - var f = form.bind({field1: 'data one'}); + var f = form.bind({ field1: 'data one' }); t.equal(f.fields.field1.value, 'data one'); t.equal(f.fields.field1.data, 'data one'); t.equal(f.fields.field1.error, undefined); @@ -60,7 +60,7 @@ test('bind with missing field in data keeps field in form', function (t) { t.equal(f.bind, undefined); t.equal(f.handle, undefined); - t.deepEqual(f.data, {field1: 'data one', field2: ''}); + t.deepEqual(f.data, { field1: 'data one', field2: '' }); t.notEqual(form, f, 'bind returns new form object'); t.end(); @@ -78,7 +78,7 @@ test('validate', function (t) { }] }) }); - var data = {field1: 'data one', field2: 'data two'}; + var data = { field1: 'data one', field2: 'data two' }; form.bind(data).validate(function (err, f) { t.equal(f.fields.field1.value, 'data one'); t.equal(f.fields.field1.data, 'data one'); @@ -87,7 +87,7 @@ test('validate', function (t) { t.equal(f.fields.field2.data, 'data two'); t.equal(f.fields.field2.error, 'validation error'); - t.deepEqual(f.data, {field1: 'data one', field2: 'data two'}); + t.deepEqual(f.data, { field1: 'data one', field2: 'data two' }); t.notEqual(form, f, 'bind returns new form object'); t.notOk(f.isValid()); @@ -158,7 +158,7 @@ test('validate invalid data', function (t) { test('handle empty', function (t) { t.plan(3); - var f = forms.create({field1: forms.fields.string()}); + var f = forms.create({ field1: forms.fields.string() }); f.bind = function () { t.fail('bind should not be called'); }; @@ -187,7 +187,7 @@ test('handle empty', function (t) { test('handle success', function (t) { t.plan(8); - var f = forms.create({field1: forms.fields.string()}); + var f = forms.create({ field1: forms.fields.string() }); var callOrder = []; f.bind = function () { callOrder.push('bind'); @@ -199,7 +199,7 @@ test('handle success', function (t) { t.ok(true, 'validate called'); callback(null, f); }; - f.handle({field1: 'test'}, { + f.handle({ field1: 'test' }, { empty: function () { t.fail('empty should not be called'); }, @@ -214,7 +214,7 @@ test('handle success', function (t) { t.fail('other should not be called'); } }); - f.handle({field1: 'test'}, { + f.handle({ field1: 'test' }, { other: function () { t.ok(true, 'other called'); t.equal(callOrder.length, 2); @@ -225,7 +225,7 @@ test('handle success', function (t) { test('handle empty object', function (t) { t.plan(3); - var f = forms.create({field1: forms.fields.string()}); + var f = forms.create({ field1: forms.fields.string() }); f.bind = function () { t.ok(true, 'bind called'); f.fields.field1.error = 'some error'; @@ -261,7 +261,7 @@ test('handle empty object', function (t) { test('handle sends callbacks', function (t) { t.plan(9); - var f = forms.create({field1: forms.fields.string()}); + var f = forms.create({ field1: forms.fields.string() }); f.bind = function () { f.isValid = function () { return true; }; @@ -276,7 +276,7 @@ test('handle sends callbacks', function (t) { t.equal(typeof callbacks.empty, 'function'); } }); - f.handle({field1: 'test'}, { + f.handle({ field1: 'test' }, { success: function testing(form, callbacks) { t.equal(Object.keys(callbacks).length, 1); t.equal(typeof callbacks.success, 'function'); @@ -287,7 +287,7 @@ test('handle sends callbacks', function (t) { f.isValid = function () { return false; }; return f; }; - f.handle({field1: 'test'}, { + f.handle({ field1: 'test' }, { success: function yay() {}, error: function nay(form, callbacks) { t.equal(Object.keys(callbacks).length, 2); @@ -296,7 +296,7 @@ test('handle sends callbacks', function (t) { } }); - f.handle({field1: 'test'}, { + f.handle({ field1: 'test' }, { other: function testing(form, callbacks) { t.equal(Object.keys(callbacks).length, 1); t.equal(typeof callbacks.other, 'function'); @@ -312,13 +312,13 @@ test('handle missing multi-form section', function (t) { section1: { field1: forms.fields.string() }, section2: { field1: forms.fields.string() } }); - f.bind({section1: { field1: 'string' }}); + f.bind({ section1: { field1: 'string' } }); t.ok(true, 'Form handled missing section ok.'); }); test('handle error', function (t) { t.plan(5); - var f = forms.create({field1: forms.fields.string()}); + var f = forms.create({ field1: forms.fields.string() }); f.bind = function () { t.ok(true, 'bind called'); f.fields.field1.error = 'some error'; @@ -329,7 +329,7 @@ test('handle error', function (t) { t.ok(true, 'validate called'); callback(null, f); }; - f.handle({foo: 'bar'}, { + f.handle({ foo: 'bar' }, { empty: function () { t.fail('empty should not be called'); }, @@ -354,7 +354,7 @@ test('handle error', function (t) { test('handle ServerRequest GET', function (t) { t.plan(1); - var f = forms.create({field1: forms.fields.string()}), + var f = forms.create({ field1: forms.fields.string() }), req = new http.IncomingMessage(); req.method = 'GET'; req.url = '/?field1=test'; @@ -368,9 +368,9 @@ test('handle ServerRequest GET', function (t) { test('handle ServerRequest POST', function (t) { t.plan(1); - var f = forms.create({field1: forms.fields.string()}), + var f = forms.create({ field1: forms.fields.string() }), req = new http.IncomingMessage(); - req.body = {field1: 'test'}; + req.body = { field1: 'test' }; req.method = 'POST'; f.handle(req, { success: function (form) { @@ -422,9 +422,9 @@ test('validates past first error with validatePastFirstError option', function ( test('handle ServerRequest POST with bodyDecoder', function (t) { t.plan(1); - var f = forms.create({field1: forms.fields.string()}), + var f = forms.create({ field1: forms.fields.string() }), req = new http.IncomingMessage(); - req.body = {field1: 'test'}; + req.body = { field1: 'test' }; req.method = 'POST'; f.handle(req, { success: function (form) { @@ -435,7 +435,7 @@ test('handle ServerRequest POST with bodyDecoder', function (t) { }); test('div', function (t) { - var f = forms.create({fieldname: forms.fields.string()}); + var f = forms.create({ fieldname: forms.fields.string() }); t.equal( f.toHTML(), '