Skip to content

Commit 21d516c

Browse files
committed
input element upgraded to v2.0
1 parent 5a22bd9 commit 21d516c

File tree

2 files changed

+74
-69
lines changed

2 files changed

+74
-69
lines changed

src/directives/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ export default function(Vue){
99
if ( !binding.value ) return;
1010

1111
Object.keys(binding.value).forEach((key) => {
12-
el.setAttribute(key, value[key]);
12+
el.setAttribute(key, binding.value[key]);
1313
});
1414

1515
}
1616
});
1717

18-
18+
/**
19+
* In Vue 2.0 we cannot bind the :type and v-model at the same time.
20+
* They recommended using if statements to render our elements, but that's just ridiculous for a project like this
21+
* So instead we'll use this directive to add the type when the element is bound
22+
*/
1923
Vue.directive('formly-input-type', {
2024
bind: function(el, binding){
2125
if ( !binding.value ) return;

test/unit/specs/index.spec.js

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ function describeFunctions(formlyElement, inputElement, inputType = 'text', opti
102102

103103
function describeAttributes(inputElement, testPlaceholder = true){
104104
beforeEach(()=>{
105-
data.form.test.type = inputElement;
106-
data.form.test.inputType = 'text';
105+
data.fields[0].type = inputElement;
106+
data.fields[0].templateOptions.type = 'text';
107107
});
108108

109109
it('attributes', () => {
110-
data.form.test.atts = {
110+
data.fields[0].templateOptions.atts = {
111111
'data-foo': 'bar',
112112
'data-bar': 'foo',
113113
'placeholder': 'holding'
@@ -120,7 +120,7 @@ function describeAttributes(inputElement, testPlaceholder = true){
120120
});
121121

122122
it('classes', () => {
123-
data.form.test.classes = {
123+
data.fields[0].templateOptions.classes = {
124124
'class-a': true,
125125
'class-b': false
126126
};
@@ -130,25 +130,25 @@ function describeAttributes(inputElement, testPlaceholder = true){
130130
});
131131

132132
it('id', () => {
133-
data.form.test.id = 'someId';
133+
data.fields[0].templateOptions.id = 'someId';
134134
createForm();
135135
let input = vm.$el.querySelectorAll(inputElement)[0];
136136
let label = vm.$el.querySelectorAll('label')[0];
137-
expect(input.id).to.equal(data.form.test.id);
138-
expect(label.htmlFor).to.equal(data.form.test.id);
137+
expect(input.id).to.equal(data.fields[0].templateOptions.id);
138+
expect(label.htmlFor).to.equal(data.fields[0].templateOptions.id);
139139
});
140140
};
141141

142142
function describeConditional(inputElement){
143143
it('label', (done) => {
144-
data.form.test.type = inputElement;
145-
data.form.test.inputType = 'text';
146-
data.form.test.label = '';
144+
data.fields[0].type = inputElement;
145+
data.fields[0].templateOptions.type = 'text';
146+
data.fields[0].templateOptions.label = '';
147147
createForm(data);
148148

149149
expect(vm.$el.querySelectorAll('label')).to.be.length(0);
150150

151-
vm.form.test.label = 'testing';
151+
vm.fields[0].templateOptions.label = 'testing';
152152

153153
setTimeout(()=>{
154154
expect(vm.$el.querySelectorAll('label')).to.be.length(1);
@@ -184,7 +184,7 @@ describe('Bootstrap Field Inputs', () => {
184184
});
185185

186186
describe('classes & attributes', () => {
187-
//describeAttributes('input');
187+
describeAttributes('input');
188188
it('should have input type as a class', () => {
189189
data.fields[0].type = 'input';
190190
data.fields[0].templateOptions.type = 'text';
@@ -195,61 +195,62 @@ describe('Bootstrap Field Inputs', () => {
195195
});
196196
});
197197

198-
/*
199-
describe('conditional elements', ()=>{
200-
describeConditional('input');
201-
});
202-
203-
it('layout', (done) => {
204-
data.form.test.type = 'input';
205-
data.form.test.inputType = 'text';
206-
createForm(data);
207-
208-
let inputs = vm.$el.querySelectorAll('input');
209-
let input = inputs[0];
210-
let labels = vm.$el.querySelectorAll('label');
211-
let label = labels[0];
212-
213-
expect(inputs).to.be.length(1);
214-
expect(input.type).to.equal('text');
215-
expect(input.className).to.equal('form-control');
216-
217-
vm.form.test.value = 'testing';
218-
219-
setTimeout(() => {
220-
expect(vm.$el.querySelectorAll('input')[0].value).to.equal('testing');
221-
done();
222-
}, 0);
223-
224-
});
225-
226-
it('adds active and focus classes', (done) => {
227-
data.form.test.type = 'input';
228-
data.form.test.inputType = 'text';
229-
createForm(data);
230-
231-
expect(vm.$el.querySelectorAll('.formly-has-focus')).to.be.length(0);
232-
expect(vm.$el.querySelectorAll('.formly-has-value')).to.be.length(0);
233-
234-
trigger(vm.$el.querySelectorAll('input')[0], 'focus');
235-
data.form.test.value = 'test';
236-
setTimeout(()=>{
237-
expect(vm.$el.querySelectorAll('.formly-has-focus')).to.be.length(1);
238-
expect(vm.$el.querySelectorAll('.formly-has-value')).to.be.length(1);
239-
done();
240-
},0);
241-
});
242-
243-
it('defaults to text', () => {
244-
data.form.test.type = 'input';
245-
data.form.test.inputType = '';
246-
createForm(data);
247-
248-
let inputs = vm.$el.querySelectorAll('input');
249-
let input = inputs[0];
250-
expect(input.type).to.equal('text');
251-
});
252-
*/
198+
199+
describe('conditional elements', ()=>{
200+
describeConditional('input');
201+
});
202+
203+
204+
it('layout', (done) => {
205+
data.fields[0].type = 'input';
206+
data.fields[0].templateOptions.type = 'text';
207+
createForm(data);
208+
209+
let inputs = vm.$el.querySelectorAll('input');
210+
let input = inputs[0];
211+
let labels = vm.$el.querySelectorAll('label');
212+
let label = labels[0];
213+
214+
expect(inputs).to.be.length(1);
215+
expect(input.type).to.equal('text');
216+
expect(input.className).to.equal('form-control');
217+
218+
vm.model.test = 'testing';
219+
220+
setTimeout(() => {
221+
expect(vm.$el.querySelectorAll('input')[0].value).to.equal('testing');
222+
done();
223+
}, 0);
224+
225+
});
226+
227+
it('adds active and focus classes', (done) => {
228+
data.fields[0].type = 'input';
229+
data.fields[0].templateOptions.type = 'text';
230+
createForm(data);
231+
232+
expect(vm.$el.querySelectorAll('.formly-has-focus')).to.be.length(0);
233+
expect(vm.$el.querySelectorAll('.formly-has-value')).to.be.length(0);
234+
235+
trigger(vm.$el.querySelectorAll('input')[0], 'focus');
236+
data.model.test = 'test';
237+
setTimeout(()=>{
238+
expect(vm.$el.querySelectorAll('.formly-has-focus')).to.be.length(1);
239+
expect(vm.$el.querySelectorAll('.formly-has-value')).to.be.length(1);
240+
done();
241+
},0);
242+
});
243+
244+
it('defaults to text', () => {
245+
data.fields[0].type = 'input';
246+
data.fields[0].templateOptions.type = undefined;
247+
createForm(data);
248+
249+
let inputs = vm.$el.querySelectorAll('input');
250+
let input = inputs[0];
251+
expect(input.type).to.equal('text');
252+
});
253+
253254
});
254255

255256

0 commit comments

Comments
 (0)