Skip to content

Commit 9c6c8d8

Browse files
committed
checklist input name
Use `name` in checklist input fields. Fix vue-generators#243
1 parent a8f09ae commit 9c6c8d8

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

dev/checklist/app.vue

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
label: "Skills",
2424
model: "skills",
2525
required: true,
26+
inputName:"skill",
2627
min: 2,
2728
listBox: true,
2829
values: ["HTML5", "Javascript", "CSS3", "CoffeeScript", "AngularJS", "ReactJS", "VueJS"],

src/fields/core/fieldChecklist.vue

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.listbox.form-control(v-if="schema.listBox", :disabled="disabled")
44
.list-row(v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
55
label
6-
input(type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)")
6+
input(type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)" :name="getInputName(item)")
77
| {{ getItemName(item) }}
88

99
.combobox.form-control(v-if="!schema.listBox", :disabled="disabled")
@@ -14,7 +14,7 @@
1414
.dropList
1515
.list-row(v-if="comboExpanded", v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
1616
label
17-
input(type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)")
17+
input(type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)" :name="getInputName(item)")
1818
| {{ getItemName(item) }}
1919
</template>
2020

@@ -45,10 +45,18 @@
4545
return this.value.length;
4646
4747
return 0;
48-
}
48+
}
4949
},
5050
5151
methods: {
52+
53+
getInputName(item){
54+
if(this.schema && this.schema.inputName && this.schema.inputName.length > 0){
55+
return this.schema.inputName + "_" + this.getItemValue(item);
56+
}
57+
return this.getItemValue(item);
58+
},
59+
5260
getItemValue(item) {
5361
if (isObject(item)){
5462
if (typeof this.schema["checklistOptions"] !== "undefined" && typeof this.schema["checklistOptions"]["value"] !== "undefined") {

test/unit/specs/fields/fieldChecklist.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ describe("fieldChecklist.vue", function() {
524524
type: "checklist",
525525
label: "Skills",
526526
model: "skills",
527+
inputName:"",
527528
values: [
528529
"HTML5",
529530
"Javascript",
@@ -581,6 +582,39 @@ describe("fieldChecklist.vue", function() {
581582
done();
582583
});
583584
});
585+
586+
it("should contain input name field withouth inputName", (done) => {
587+
588+
checkboxes = dropList.querySelectorAll("input[type=checkbox]");
589+
expect(checkboxes[0].name).to.be.equal("HTML5");
590+
expect(checkboxes[1].name).to.be.equal("Javascript");
591+
expect(checkboxes[2].name).to.be.equal("CSS3");
592+
expect(checkboxes[3].name).to.be.equal("CoffeeScript");
593+
expect(checkboxes[4].name).to.be.equal("AngularJS");
594+
expect(checkboxes[5].name).to.be.equal("ReactJS");
595+
expect(checkboxes[6].name).to.be.equal("VueJS");
596+
597+
done();
598+
599+
});
600+
601+
it("should contain input name field with inputName", (done) => {
602+
603+
schema.inputName="skill";
604+
605+
vm.$nextTick( () => {
606+
checkboxes = dropList.querySelectorAll("input[type=checkbox]");
607+
expect(checkboxes[0].name).to.be.equal("skill_HTML5");
608+
expect(checkboxes[1].name).to.be.equal("skill_Javascript");
609+
expect(checkboxes[2].name).to.be.equal("skill_CSS3");
610+
expect(checkboxes[3].name).to.be.equal("skill_CoffeeScript");
611+
expect(checkboxes[4].name).to.be.equal("skill_AngularJS");
612+
expect(checkboxes[5].name).to.be.equal("skill_ReactJS");
613+
expect(checkboxes[6].name).to.be.equal("skill_VueJS");
614+
615+
done();
616+
});
617+
});
584618

585619
it("should checked the values", () => {
586620
expect(isChecked(0)).to.be.false;

0 commit comments

Comments
 (0)