Skip to content

Commit 11d856f

Browse files
committed
added select input
1 parent fab13aa commit 11d856f

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

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": "0.1.4",
3+
"version": "0.2.0",
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,7 +1,7 @@
11
<template>
22
<div class="form-group">
33
<label v-if="form[key].label" :for="form[key].id ? form[key].id : null">{{form[key].label}}</label>
4-
<input class="form-control" :class="form[key].classes" :id="form[key].id ? form[key].id : null" :type="form[key].inputType" v-model="form[key].value" :placeholder="form[key].placeholder" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="form[key].atts">
4+
<input class="form-control" :class="form[key].classes" :id="form[key].id ? form[key].id : null" :type="form[key].inputType" v-model="form[key].value" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="form[key].atts">
55
</div>
66
</template>
77

src/fields/fieldSelect.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="form-group">
33
<label v-if="form[key].label" :for="form[key].id ? form[key].id : null">{{form[key].label}}</label>
44
<select class="form-control" :class="form[key].classes" :id="form[key].id ? form[key].id : null" v-model="form[key].value" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="form[key].atts">
5+
<option v-for="option in form[key].options" :value="option.value || option">{{option.label || option}}</option>
56
</select>
67
</div>
78
</template>

test/unit/specs/index.spec.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,26 @@ function describeFunctions(inputElement){
9595
});
9696
};
9797

98-
function describeAttributes(inputElement, exclude = []){
98+
function describeAttributes(inputElement, testPlaceholder = true){
9999
beforeEach(()=>{
100100
data.form.test.type = inputElement;
101101
data.form.test.inputType = 'text';
102102
});
103103

104104
it('attributes', () => {
105-
if ( exclude.indexOf('attributes') >= 0 ) return true;
106105
data.form.test.atts = {
107106
'data-foo': 'bar',
108-
'data-bar': 'foo'
107+
'data-bar': 'foo',
108+
'placeholder': 'holding'
109109
};
110110
createForm();
111111
let input = vm.$el.querySelectorAll(inputElement)[0];
112112
expect(input.dataset.foo).to.equal('bar');
113113
expect(input.dataset.bar).to.equal('foo');
114+
if ( testPlaceholder ) expect(input.placeholder).to.equal('holding');
114115
});
115116

116117
it('classes', () => {
117-
if ( exclude.indexOf('classes') >= 0 ) return true;
118118
data.form.test.classes = {
119119
'class-a': true,
120120
'class-b': false
@@ -124,18 +124,7 @@ function describeAttributes(inputElement, exclude = []){
124124
expect(input.className).to.equal('form-control class-a');
125125
});
126126

127-
128-
129-
it('placeholder', () => {
130-
if ( exclude.indexOf('placeholder') >= 0 ) return;
131-
data.form.test.placeholder = 'holding';
132-
createForm();
133-
let input = vm.$el.querySelectorAll(inputElement)[0];
134-
expect(input.placeholder).to.equal('holding');
135-
});
136-
137127
it('id', () => {
138-
if ( exclude.indexOf('id') >= 0 ) return true;
139128
data.form.test.id = 'someId';
140129
createForm();
141130
let input = vm.$el.querySelectorAll(inputElement)[0];
@@ -219,7 +208,7 @@ describe('Bootstrap Field Inputs', () => {
219208
describeFunctions('select');
220209
});
221210
describe('classes & attributes', () => {
222-
describeAttributes('select', ['placeholder']);
211+
describeAttributes('select', false);
223212
});
224213
describe('conditional elements', ()=>{
225214
describeConditional('select');
@@ -234,6 +223,31 @@ describe('Bootstrap Field Inputs', () => {
234223

235224
expect(inputs).to.be.length(1);
236225
});
226+
227+
it('array options', () => {
228+
data.form.test.type = 'select';
229+
data.form.test.options = ['one', 'two', 'three'];
230+
createForm();
231+
let options = vm.$el.querySelectorAll('option');
232+
let option = options[0];
233+
expect(options).to.be.length(3);
234+
expect(option.value).to.equal('one');
235+
expect(option.innerHTML).to.equal('one');
236+
});
237+
238+
it('object options', () => {
239+
data.form.test.type = 'select';
240+
data.form.test.options = [
241+
{ label: 'Foo', value: 'bar' },
242+
{ label: 'Bar', value: 'foo' }
243+
];
244+
createForm();
245+
let options = vm.$el.querySelectorAll('option');
246+
let option = options[0];
247+
expect(options).to.be.length(2);
248+
expect(option.value).to.equal('bar');
249+
expect(option.innerHTML).to.equal('Foo');
250+
});
237251

238252
});
239253

0 commit comments

Comments
 (0)