Skip to content

Commit

Permalink
checklist input name
Browse files Browse the repository at this point in the history
Use `name` in checklist input fields. Fix #243
  • Loading branch information
hansi90 committed Oct 10, 2017
1 parent a8f09ae commit 9c6c8d8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions dev/checklist/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default {
label: "Skills",
model: "skills",
required: true,
inputName:"skill",
min: 2,
listBox: true,
values: ["HTML5", "Javascript", "CSS3", "CoffeeScript", "AngularJS", "ReactJS", "VueJS"],
Expand Down
14 changes: 11 additions & 3 deletions src/fields/core/fieldChecklist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.listbox.form-control(v-if="schema.listBox", :disabled="disabled")
.list-row(v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
label
input(type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)")
input(type="checkbox", :checked="isItemChecked(item)", :disabled="disabled", @change="onChanged($event, item)" :name="getInputName(item)")
| {{ getItemName(item) }}

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

Expand Down Expand Up @@ -45,10 +45,18 @@
return this.value.length;
return 0;
}
}
},
methods: {
getInputName(item){
if(this.schema && this.schema.inputName && this.schema.inputName.length > 0){
return this.schema.inputName + "_" + this.getItemValue(item);
}
return this.getItemValue(item);
},
getItemValue(item) {
if (isObject(item)){
if (typeof this.schema["checklistOptions"] !== "undefined" && typeof this.schema["checklistOptions"]["value"] !== "undefined") {
Expand Down
34 changes: 34 additions & 0 deletions test/unit/specs/fields/fieldChecklist.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ describe("fieldChecklist.vue", function() {
type: "checklist",
label: "Skills",
model: "skills",
inputName:"",
values: [
"HTML5",
"Javascript",
Expand Down Expand Up @@ -581,6 +582,39 @@ describe("fieldChecklist.vue", function() {
done();
});
});

it("should contain input name field withouth inputName", (done) => {

checkboxes = dropList.querySelectorAll("input[type=checkbox]");
expect(checkboxes[0].name).to.be.equal("HTML5");
expect(checkboxes[1].name).to.be.equal("Javascript");
expect(checkboxes[2].name).to.be.equal("CSS3");
expect(checkboxes[3].name).to.be.equal("CoffeeScript");
expect(checkboxes[4].name).to.be.equal("AngularJS");
expect(checkboxes[5].name).to.be.equal("ReactJS");
expect(checkboxes[6].name).to.be.equal("VueJS");

done();

});

it("should contain input name field with inputName", (done) => {

schema.inputName="skill";

vm.$nextTick( () => {
checkboxes = dropList.querySelectorAll("input[type=checkbox]");
expect(checkboxes[0].name).to.be.equal("skill_HTML5");
expect(checkboxes[1].name).to.be.equal("skill_Javascript");
expect(checkboxes[2].name).to.be.equal("skill_CSS3");
expect(checkboxes[3].name).to.be.equal("skill_CoffeeScript");
expect(checkboxes[4].name).to.be.equal("skill_AngularJS");
expect(checkboxes[5].name).to.be.equal("skill_ReactJS");
expect(checkboxes[6].name).to.be.equal("skill_VueJS");

done();
});
});

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

0 comments on commit 9c6c8d8

Please sign in to comment.