Comparing version 0.1.5 to 0.1.6
@@ -38,2 +38,4 @@ | ||
this.value = this.options.value || undefined; | ||
for (var i = 0; i < this.options.options.length; i++) { | ||
@@ -82,5 +84,13 @@ | ||
var tag = new Tag('option', this.options.options[i].attributes, this.options.options[i].label); | ||
content = content + tag.render(); | ||
var optionTag, | ||
attr = this.options.options[i].attributes; | ||
// determine if this option is selected | ||
if (this.value === (this.options.options[i].value || this.options.options[i].label)) { | ||
attr.selected = true; | ||
} | ||
optionTag = new Tag('option', attr, this.options.options[i].label); | ||
content = content + optionTag.render(); | ||
} | ||
@@ -87,0 +97,0 @@ |
{ | ||
"name": "formist", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "A library to publish, consume and validate HTML5 forms.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -518,2 +518,45 @@ | ||
describe("with a selected option", function () { | ||
it("as an array of strings", function () { | ||
form.add(new formist.Field('select', { | ||
options: ['Australia','UK','US'], | ||
value: 'UK' | ||
})); | ||
expect(form.render()).to.equal('<form><div class="field"><select><option>Australia</option><option selected>UK</option><option>US</option></select></div></form>'); | ||
}); | ||
it("as an array of objects (label only)", function () { | ||
form.add(new formist.Field('select', { | ||
options: [{label:'Australia'},{label:'UK'},{label:'US'}], | ||
value: 'US' | ||
})); | ||
expect(form.render()).to.equal('<form><div class="field"><select><option>Australia</option><option>UK</option><option selected>US</option></select></div></form>'); | ||
}); | ||
it("as an array of objects (label and value)", function () { | ||
form.add(new formist.Field('select', { | ||
options: [{label:'Australia',value:'a'},{label:'UK',value:'uk'},{label:'US',value:'us'}], | ||
value: 'a' | ||
})); | ||
expect(form.render()).to.equal('<form><div class="field"><select><option value="a" selected>Australia</option><option value="uk">UK</option><option value="us">US</option></select></div></form>'); | ||
}); | ||
it("as an array of objects with a selected attribute", function () { | ||
form.add(new formist.Field('select', { | ||
options: [{label:'Australia',value:'a',attributes:{selected:true}},{label:'UK',value:'uk'},{label:'US',value:'us',attributes:{disabled:true}}] | ||
})); | ||
expect(form.render()).to.equal('<form><div class="field"><select><option selected value="a">Australia</option><option value="uk">UK</option><option disabled value="us">US</option></select></div></form>'); | ||
}); | ||
}); | ||
}); | ||
@@ -520,0 +563,0 @@ |
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
52710
1327