Skip to content

Commit 213c3ae

Browse files
committed
added better support for classes
1 parent 3be8711 commit 213c3ae

File tree

9 files changed

+22
-13
lines changed

9 files changed

+22
-13
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ These options are used by all the different field types. Some fields may have sp
105105
| Property | Type | Default | Description |
106106
| --- | --- | --- | --- |
107107
| options | `array` | `null` | Pass either an array of strings or objects. Objects require a `label` and `value` property. If a string is passed then it will be used for the value and the label. eg: `options: ['Foo', 'Bar']` or `options: [{ label: 'Foo', value: 'bar'},{label: 'Bar', value: 'foo'}]` |
108+
| labelClasses | `object` | `null` | Pass an object of classes to be added to the label surrounding the element. Follows the Vue bindings where each key matches a boolean value. eg `{ 'class-a': true, 'class-b': false }` In this case class-a will be attached. You may also pass an array. |
108109

109110
### Template Options
110111
These should be added to the `templateOptions` property. Some input types may have specific options which can be used here and will be specified below.
@@ -119,7 +120,8 @@ These should be added to the `templateOptions` property. Some input types may ha
119120
| onKeyup | `function(e)` | `null` | A function to run on @keyup event |
120121
| onKeydown | `function(e)` | `null` | A function to run on @keydown event |
121122
| atts | `object` | `null` | Pass an object of attributes to be added to the element. eg `{ placeholder: 'hello world' }` |
122-
| classes | `object` | `null` | Pass an object of classes to be added to the element. Follows the Vue bindings where each key matches a boolean value. eg `{ 'class-a': true, 'class-b': false }` In this case class-a will be attached. |
123+
| classes | `object` | `null` | Pass an object of classes to be added to the element. Follows the Vue bindings where each key matches a boolean value. eg `{ 'class-a': true, 'class-b': false }` In this case class-a will be attached. You may also pass an array |
124+
| wrapperClasses | `object` | `null` | Pass an object of classes to be added to the wrapper. Follows the Vue bindings where each key matches a boolean value. eg `{ 'class-a': true, 'class-b': false }` In this case class-a will be attached. You may also pass an array |
123125
| id | `string` | `null` | An ID string to attach to the element |
124126

125127
#### Input options

dist/vue-formly-bootstrap.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-formly-bootstrap.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-formly-bootstrap",
3-
"version": "2.2.4",
3+
"version": "2.2.5",
44
"description": "A bootstrap based form input bundle for Vue Formly",
55
"main": "dist/vue-formly-bootstrap.js",
66
"scripts": {

src/fields/fieldInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="form-group formly-input" :class="[ to.inputType, {'formly-has-value': model[field.key], 'formly-has-focus': form[field.key].$active, 'has-error has-danger': hasError}]">
2+
<div class="form-group formly-input" :class="[ to.inputType, to.wrapperClasses, {'formly-has-value': model[field.key], 'formly-has-focus': form[field.key].$active, 'has-error has-danger': hasError}]">
33
<label v-if="to.label" :for="to.id ? to.id : null">{{to.label}}</label>
44
<input class="form-control" :class="to.classes" :id="to.id ? to.id : null" type="text" v-model="model[field.key]" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts" v-formly-input-type="to.inputType">
55
<error-display :form="form" :field="field.key"></error-display>

src/fields/fieldList.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
2-
<div class="checkbox formly-list" :id="to.id" :class="[to.classes, {'has-error has-danger': hasError}]">
2+
<div class="checkbox formly-list" :id="to.id" :class="[to.wrapperClasses, {'has-error has-danger': hasError}]">
33

4-
<label v-for="option in field.options">
5-
<input v-if="!to.inputType || to.inputType == 'checkbox'" type="checkbox" v-model="model[field.key]" :value="option.value || option" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts">
6-
<input v-if="to.inputType == 'radio'" type="radio" v-model="model[field.key]" :value="option.value || option" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts">
4+
<label v-for="option in field.options" :class="to.labelClasses">
5+
<input v-if="!to.inputType || to.inputType == 'checkbox'" type="checkbox" v-model="model[field.key]" :value="option.value || option" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts" :class="to.classes">
6+
<input v-if="to.inputType == 'radio'" type="radio" v-model="model[field.key]" :value="option.value || option" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts" :class="to.classes">
77
{{option.label || option}}
88
</label>
99
<error-display :form="form" :field="field.key"></error-display>

src/fields/fieldSelect.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="form-group formly-select" :class="{'has-error has-danger': hasError}">
2+
<div class="form-group formly-select" :class="[to.wrapperClasses, {'has-error has-danger': hasError}]">
33
<label v-if="to.label" :for="to.id ? to.id : null">{{to.label}}</label>
44
<select class="form-control" :class="to.classes" :id="to.id ? to.id : null" v-model="model[field.key]" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts">
55
<option v-for="option in field.options" :value="option.value || option">{{option.label || option}}</option>

src/fields/fieldTextarea.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="form-group formly-textarea" :class="{'formly-has-value': model[field.key], 'formly-has-focus': form[field.key].$active, 'has-error has-danger': hasError}">
2+
<div class="form-group formly-textarea" :class="[to.wrapperClasses, {'formly-has-value': model[field.key], 'formly-has-focus': form[field.key].$active, 'has-error has-danger': hasError}]">
33
<label v-if="to.label" :for="to.id ? to.id : null">{{to.label}}</label>
44
<textarea class="form-control" :class="to.classes" :id="to.id ? to.id : null" v-model="model[field.key]" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts"></textarea>
55
<error-display :form="form" :field="field.key"></error-display>

test/unit/specs/index.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,20 @@ function describeAttributes(inputElement, testPlaceholder = true){
120120
});
121121

122122
it('classes', () => {
123+
data.fields[0].templateOptions.wrapperClasses = ['foo', 'bar'];
123124
data.fields[0].templateOptions.classes = {
124125
'class-a': true,
125126
'class-b': false
126127
};
127128
createForm();
128129
let input = vm.$el.querySelectorAll(inputElement)[0];
129130
expect(input.className).to.equal('form-control class-a');
131+
132+
let foos = vm.$el.querySelectorAll('.foo');
133+
expect(foos).to.be.length(1);
134+
135+
let fooBars = vm.$el.querySelectorAll('.bar.foo');
136+
expect(fooBars).to.be.length(1);
130137
});
131138

132139
it('id', () => {

0 commit comments

Comments
 (0)