Skip to content

Commit ee79516

Browse files
committed
added has-focus and has-value classes to input
1 parent 317fc33 commit ee79516

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
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": "1.0.0",
3+
"version": "1.0.1",
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">
2+
<div class="form-group formly-input" :class="{'formly-has-value': form[key].value, 'formly-has-focus': form[key].$active}">
33
<label v-if="form[key].label" :for="form[key].id ? form[key].id : null">{{form[key].label}}</label>
44
<input class="form-control" :class="form[key].classes" :id="form[key].id ? form[key].id : null" :type="form[key].inputType || text" 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>

test/unit/specs/index.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,23 @@ describe('Bootstrap Field Inputs', () => {
201201

202202
});
203203

204+
it('adds active and focus classes', (done) => {
205+
data.form.test.type = 'input';
206+
data.form.test.inputType = 'text';
207+
createForm(data);
208+
209+
expect(vm.$el.querySelectorAll('.formly-has-focus')).to.be.length(0);
210+
expect(vm.$el.querySelectorAll('.formly-has-value')).to.be.length(0);
211+
212+
trigger(vm.$el.querySelectorAll('input')[0], 'focus');
213+
data.form.test.value = 'test';
214+
setTimeout(()=>{
215+
expect(vm.$el.querySelectorAll('.formly-has-focus')).to.be.length(1);
216+
expect(vm.$el.querySelectorAll('.formly-has-value')).to.be.length(1);
217+
done();
218+
},0);
219+
});
220+
204221
it('defaults to text', () => {
205222
data.form.test.type = 'input';
206223
data.form.test.inputType = '';

0 commit comments

Comments
 (0)