Skip to content

Commit

Permalink
added css classes for core fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vuchl committed Sep 19, 2017
1 parent 5099907 commit 05a98eb
Show file tree
Hide file tree
Showing 18 changed files with 9,536 additions and 16 deletions.
9,448 changes: 9,448 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,5 @@
"webpack-dev-server": "1.16.2",
"webpack-merge": "0.14.1"
},
"dependencies": {
}
"dependencies": {}
}
6 changes: 5 additions & 1 deletion src/fields/abstractField.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
"model",
"schema",
"formOptions",
"disabled"
"disabled",
],

data() {
Expand Down Expand Up @@ -167,6 +167,10 @@ export default {
getFieldID(schema) {
const idPrefix = this.formOptions && this.formOptions.fieldIdPrefix ? this.formOptions.fieldIdPrefix : "";
return slugifyFormID(schema, idPrefix);
},

getFieldClasses() {
return this.schema.classes || [];
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/fields/core/fieldCheckbox.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
input(type="checkbox", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :name="schema.inputName")
input(type="checkbox", v-model="value", :autocomplete="schema.autocomplete", :disabled="disabled", :name="schema.inputName" :class="schema.classes")
</template>

<script>
Expand Down
1 change: 1 addition & 0 deletions src/fields/core/fieldInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:value="value",
@input="value = $event.target.value",
@change="onChange",
:class="schema.classes",
:disabled="disabled",
:accept="schema.accept",
:alt="schema.alt",
Expand Down
2 changes: 1 addition & 1 deletion src/fields/core/fieldLabel.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
span(:id="getFieldID(schema)") {{ value }}
span(:id="getFieldID(schema)" :class="schema.classes") {{ value }}
</template>

<script>
Expand Down
2 changes: 1 addition & 1 deletion src/fields/core/fieldRadios.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
.radio-list(:disabled="disabled")
label(v-for="item in items", :class="{'is-checked': isItemChecked(item)}")
input(type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)" )
input(type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)" :class="schema.classes")
| {{ getItemName(item) }}

</template>
Expand Down
2 changes: 1 addition & 1 deletion src/fields/core/fieldSelect.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
select.form-control(v-model="value", :disabled="disabled", :name="schema.inputName", :id="getFieldID(schema)")
select.form-control(v-model="value", :disabled="disabled", :name="schema.inputName", :id="getFieldID(schema)" :class="schema.classes")
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="schema.required", :value="null", :selected="value == undefined") {{ selectOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}
option(v-for="item in items", :value="getItemValue(item)") {{ getItemName(item) }}
</template>
Expand Down
2 changes: 1 addition & 1 deletion src/fields/core/fieldSubmit.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
input(type="submit", :value="schema.buttonText", @click="click", :name="schema.inputName", :disabled="disabled")
input(type="submit", :value="schema.buttonText", @click="click", :name="schema.inputName", :disabled="disabled" :class="schema.classes")
</template>

<script>
Expand Down
1 change: 1 addition & 0 deletions src/fields/core/fieldTextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
textarea.form-control(
v-model="value",
:id="getFieldID(schema)",
:class="schema.classes",
:disabled="disabled",
:maxlength="schema.max",
:minlength="schema.min",
Expand Down
23 changes: 23 additions & 0 deletions test/unit/specs/fields/abstractField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,27 @@ describe("abstractField.vue", function() {

});

describe("check classes application to fields", () => {

let schema = {
type: "text",
label: "First Name",
model: "user__model",
inputName: "input_name",
classes: ["applied-class", "another-class"]
};
let model = {};

before( () => {
createField(this, schema, model);
});

it("should have 2 classes ('applied-class' and 'another-class')", () => {
expect(field.getFieldClasses().length).to.be.equal(2);
expect(field.getFieldClasses()[0]).to.be.equal("applied-class");
expect(field.getFieldClasses()[1]).to.be.equal("another-class");
});

});

});
8 changes: 7 additions & 1 deletion test/unit/specs/fields/fieldCheckbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe("FieldCheckbox.vue", function() {
let schema = {
type: "checkbox",
label: "Status",
model: "status"
model: "status",
classes: ["applied-class", "another-class"]
};
let model = { status: true };
let input;
Expand Down Expand Up @@ -73,6 +74,11 @@ describe("FieldCheckbox.vue", function() {

});

it("should have 2 classes", () => {
expect(input.className.indexOf("applied-class")).not.to.be.equal(-1);
expect(input.className.indexOf("another-class")).not.to.be.equal(-1);
});

});

});
8 changes: 7 additions & 1 deletion test/unit/specs/fields/fieldInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe("fieldInput.vue", function() {
model: "name",
autocomplete: "off",
placeholder: "Field placeholder",
readonly: false
readonly: false,
classes: ["applied-class", "another-class"]
};
let model = { name: "John Doe" };
let input;
Expand Down Expand Up @@ -120,6 +121,11 @@ describe("fieldInput.vue", function() {

});

it("should have 2 classes", () => {
expect(input.className.indexOf("applied-class")).not.to.be.equal(-1);
expect(input.className.indexOf("another-class")).not.to.be.equal(-1);
});

});

});
8 changes: 7 additions & 1 deletion test/unit/specs/fields/fieldLabel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe("fieldLabel.vue", function() {
let schema = {
type: "label",
label: "Timestamp",
model: "timestamp"
model: "timestamp",
classes: ["applied-class", "another-class"]
};
let model = { timestamp: "2 days ago" };
let span;
Expand Down Expand Up @@ -51,6 +52,11 @@ describe("fieldLabel.vue", function() {

});

it("should have 2 classes", () => {
expect(span.className.indexOf("applied-class")).not.to.be.equal(-1);
expect(span.className.indexOf("another-class")).not.to.be.equal(-1);
});

});

});
8 changes: 7 additions & 1 deletion test/unit/specs/fields/fieldRadios.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe("FieldRadios.vue", function() {
"AngularJS",
"ReactJS",
"VueJS"
]
],
classes: ["applied-class", "another-class"]
};
let model = { skills: "Javascript" };
let radioList;
Expand Down Expand Up @@ -76,6 +77,11 @@ describe("FieldRadios.vue", function() {
expect(labelList[6].classList.contains("is-checked")).to.be.false;
});

it("should have 2 classes", () => {
expect(radios[0].className.indexOf("applied-class")).not.to.be.equal(-1);
expect(radios[0].className.indexOf("another-class")).not.to.be.equal(-1);
});


describe("test values reactivity to changes", () => {

Expand Down
11 changes: 9 additions & 2 deletions test/unit/specs/fields/fieldSelect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe("fieldSelect.vue", function() {
"Paris",
"Rome",
"Berlin"
]
],
classes: ["applied-class", "another-class"]
};
let model = { city: "Paris" };
let input;
Expand Down Expand Up @@ -210,7 +211,8 @@ describe("fieldSelect.vue", function() {
{ id: 3, name: "Rome" },
{ id: 4, name: "Berlin" }
];
}
},
classes: ["applied-class", "another-class"]
};
let model = { city: 2 };
let input;
Expand Down Expand Up @@ -247,6 +249,11 @@ describe("fieldSelect.vue", function() {

});

it("should have 2 classes", () => {
expect(input.className.indexOf("applied-class")).not.to.be.equal(-1);
expect(input.className.indexOf("another-class")).not.to.be.equal(-1);
});

});

});
9 changes: 8 additions & 1 deletion test/unit/specs/fields/fieldSubmit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe("fieldSubmit.vue", function() {
type: "submit",
buttonText: "Submit form",
validateBeforeSubmit: false,
onSubmit() {}
onSubmit() {},
classes: ["applied-class", "another-class"]
};
let model = { name: "John Doe" };
let input;
Expand Down Expand Up @@ -72,6 +73,12 @@ describe("fieldSubmit.vue", function() {
});
});
});

it("should have 2 classes", () => {
expect(input.className.indexOf("applied-class")).not.to.be.equal(-1);
expect(input.className.indexOf("another-class")).not.to.be.equal(-1);
});

});

});
8 changes: 7 additions & 1 deletion test/unit/specs/fields/fieldTextArea.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe("fieldTextArea.vue", function() {
model: "desc",
max: 500,
placeholder: "Field placeholder",
readonly: false
readonly: false,
classes: ["applied-class", "another-class"]
};
let model = { desc: "Lorem ipsum dolor sit amet, consectetur adipiscing elit." };
let input;
Expand Down Expand Up @@ -87,6 +88,11 @@ describe("fieldTextArea.vue", function() {

});

it("should have 2 classes", () => {
expect(input.className.indexOf("applied-class")).not.to.be.equal(-1);
expect(input.className.indexOf("another-class")).not.to.be.equal(-1);
});

});

});

0 comments on commit 05a98eb

Please sign in to comment.