hmpo-template-mixins
Advanced tools
Comparing version
@@ -121,2 +121,9 @@ 'use strict'; | ||
var autocomplete; | ||
if (fields[key] && typeof fields[key].autocomplete === 'string') { | ||
autocomplete = fields[key].autocomplete; | ||
} else if (typeof extension.autocomplete === 'string' && extension.autocomplete) { | ||
autocomplete = extension.autocomplete; | ||
} | ||
return _.extend(extension, { | ||
@@ -136,2 +143,3 @@ id: key, | ||
date: extension.date, | ||
autocomplete: autocomplete, | ||
attributes: fields[key] && fields[key].attributes | ||
@@ -216,2 +224,17 @@ }); | ||
var autocomplete = fields[key] && fields[key].autocomplete || {}; | ||
if (autocomplete === 'off') { | ||
autocomplete = { | ||
day: 'off', | ||
month: 'off', | ||
year: 'off' | ||
}; | ||
} else if (typeof autocomplete === 'string') { | ||
autocomplete = { | ||
day: autocomplete + '-day', | ||
month: autocomplete + '-month', | ||
year: autocomplete + '-year' | ||
}; | ||
} | ||
var parts = [], | ||
@@ -221,8 +244,8 @@ dayPart, monthPart, yearPart; | ||
if (isExact) { | ||
dayPart = compiled['partials/forms/input-text-group'].render(inputText.call(this, key + '-day', { pattern: '[0-9]*', min: 1, max: 31, maxlength: 2, hintId: key + '-hint', date: true })); | ||
dayPart = compiled['partials/forms/input-text-group'].render(inputText.call(this, key + '-day', { pattern: '[0-9]*', min: 1, max: 31, maxlength: 2, hintId: key + '-hint', date: true, autocomplete: autocomplete.day })); | ||
parts.push(dayPart); | ||
} | ||
monthPart = compiled['partials/forms/input-text-group'].render(inputText.call(this, key + '-month', { pattern: '[0-9]*', min: 1, max: 12, maxlength: 2, hintId: key + '-hint', date: true })); | ||
yearPart = compiled['partials/forms/input-text-group'].render(inputText.call(this, key + '-year', { pattern: '[0-9]*', maxlength: 4, hintId: key + '-hint', date: true })); | ||
monthPart = compiled['partials/forms/input-text-group'].render(inputText.call(this, key + '-month', { pattern: '[0-9]*', min: 1, max: 12, maxlength: 2, hintId: key + '-hint', date: true, autocomplete: autocomplete.month })); | ||
yearPart = compiled['partials/forms/input-text-group'].render(inputText.call(this, key + '-year', { pattern: '[0-9]*', maxlength: 4, hintId: key + '-hint', date: true, autocomplete: autocomplete.year })); | ||
parts = parts.concat(monthPart, yearPart); | ||
@@ -229,0 +252,0 @@ |
{ | ||
"name": "hmpo-template-mixins", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "A middleware that exposes a series of Mustache mixins on res.locals to ease usage of forms, translations, and some general needs.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -102,2 +102,27 @@ var mixins = require('../lib/template-mixins'); | ||
it('should have an autocomplete setting if specified', function () { | ||
middleware = mixins({ | ||
'field-name': { | ||
'autocomplete': 'custom' | ||
} | ||
}); | ||
middleware(req, res, next); | ||
res.locals['input-text']().call(res.locals, 'field-name'); | ||
render.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'custom' | ||
})); | ||
}); | ||
it('should default to no autocomplete attribute ', function () { | ||
middleware = mixins({ | ||
'field-name': { | ||
} | ||
}); | ||
middleware(req, res, next); | ||
res.locals['input-text']().call(res.locals, 'field-name'); | ||
render.should.have.been.calledWith(sinon.match({ | ||
autocomplete: sinon.match.undefined | ||
})); | ||
}); | ||
it('should have classes if one or more were specified against the field', function () { | ||
@@ -363,2 +388,116 @@ middleware = mixins({ | ||
describe('autocomplete', function () { | ||
it('should have a sufix of -day -month and -year', function () { | ||
var autocompletemiddleware = mixins({ | ||
'field-name': { | ||
'autocomplete': 'bday' | ||
} | ||
}); | ||
autocompletemiddleware(req, res, next); | ||
res.locals['input-date']().call(res.locals, 'field-name'); | ||
render.called; | ||
var dayCall = render.getCall(0), | ||
monthCall = render.getCall(1), | ||
yearCall = render.getCall(2); | ||
dayCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'bday-day' | ||
})); | ||
monthCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'bday-month' | ||
})); | ||
yearCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'bday-year' | ||
})); | ||
}); | ||
it('should be set as exact values if an object is given', function () { | ||
var autocompletemiddleware = mixins({ | ||
'field-name': { | ||
'autocomplete': { | ||
day: 'day-type', | ||
month: 'month-type', | ||
year: 'year-type' | ||
} | ||
} | ||
}); | ||
autocompletemiddleware(req, res, next); | ||
res.locals['input-date']().call(res.locals, 'field-name'); | ||
render.called; | ||
var dayCall = render.getCall(0), | ||
monthCall = render.getCall(1), | ||
yearCall = render.getCall(2); | ||
dayCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'day-type' | ||
})); | ||
monthCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'month-type' | ||
})); | ||
yearCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'year-type' | ||
})); | ||
}); | ||
it('should set autocomplete to off if off is specified', function () { | ||
var autocompletemiddleware = mixins({ | ||
'field-name': { | ||
'autocomplete': 'off' | ||
} | ||
}); | ||
autocompletemiddleware(req, res, next); | ||
res.locals['input-date']().call(res.locals, 'field-name'); | ||
render.called; | ||
var dayCall = render.getCall(0), | ||
monthCall = render.getCall(1), | ||
yearCall = render.getCall(2); | ||
dayCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'off' | ||
})); | ||
monthCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'off' | ||
})); | ||
yearCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: 'off' | ||
})); | ||
}); | ||
it('should default to no attribute across all date fields', function () { | ||
middleware(req, res, next); | ||
res.locals['input-date']().call(res.locals, 'field-name'); | ||
render.called; | ||
var dayCall = render.getCall(0), | ||
monthCall = render.getCall(1), | ||
yearCall = render.getCall(2); | ||
dayCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: undefined | ||
})); | ||
monthCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: undefined | ||
})); | ||
yearCall.should.have.been.calledWith(sinon.match({ | ||
autocomplete: undefined | ||
})); | ||
}); | ||
}); | ||
it('prefixes translation lookup with namespace if provided', function () { | ||
@@ -365,0 +504,0 @@ middleware = mixins({}, { translate: translate, sharedTranslationsKey: 'name.space' }); |
Sorry, the diff of this file is not supported yet
71010
10.05%1335
11.06%