Skip to content

refactored schema.classes to schema.fieldClasses #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -172,6 +172,10 @@ export default {
return slugifyFormID(schema, idPrefix);
},

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

formatValueToField(value) {
return value;
},
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.fieldClasses")
</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 @@ -5,6 +5,7 @@
:type="schema.inputType",
:value="value",
@input="value = $event.target.value",
:class="schema.fieldClasses",
@change="schema.onChange || null",
:disabled="disabled",
:accept="schema.accept",
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.fieldClasses") {{ 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.fieldClasses")
| {{ 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.fieldClasses")
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.fieldClasses")
</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.fieldClasses",
: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",
fieldClasses: ["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",
fieldClasses: ["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,
fieldClasses: ["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",
fieldClasses: ["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"
]
],
fieldClasses: ["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"
]
],
fieldClasses: ["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" }
];
}
},
fieldClasses: ["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() {},
fieldClasses: ["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,
fieldClasses: ["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);
});

});

});