Skip to content

Commit 5a2a791

Browse files
committed
working on input
1 parent fcd33e7 commit 5a2a791

File tree

4 files changed

+108
-19
lines changed

4 files changed

+108
-19
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"babel-preset-es2015": "6.9.0",
3232
"babel-preset-es2015-loose-rollup": "^7.0.0",
3333
"babel-preset-stage-0": "6.5.0",
34+
"babel-runtime": "^6.23.0",
3435
"chai": "3.5.0",
3536
"conventional-changelog-cli": "1.2.0",
3637
"conventional-github-releaser": "1.1.3",
@@ -74,8 +75,8 @@
7475
"sinon-chai": "2.8.0",
7576
"style-loader": "0.13.1",
7677
"uglify-js": "^2.6.4",
77-
"vue": "~2.0.0",
78-
"vue-formly": "^2.3.9",
78+
"vue": "^2.2.6",
79+
"vue-formly": "^2.5.0",
7980
"vue-hot-reload-api": "1.3.2",
8081
"vue-html-loader": "1.2.3",
8182
"vue-loader": "8.5.3",

src/fields/fieldInput.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import baseField from './baseField';
2+
export default {
3+
render(h){
4+
const children = [];
5+
const self = this;
6+
7+
// add the label if it needs it
8+
if ( this.to.label ) children.push(
9+
h('label', {
10+
attrs: {
11+
'for': this.to.id
12+
}
13+
}, this.to.label )
14+
);
15+
16+
// add the input
17+
children.push(
18+
h('input', {
19+
attrs: {
20+
id: this.to.id,
21+
type: this.to.inputType || 'text',
22+
...this.to.atts
23+
},
24+
'class': {
25+
'form-control': true,
26+
...this.to.classes
27+
},
28+
domProps: {
29+
value: self.value
30+
},
31+
on: {
32+
input(event){
33+
self.value = event.target.value;
34+
self.$emit('input', event.target.value);
35+
},
36+
blur: this.onBlur,
37+
focus: this.onFocus,
38+
click: this.onClick,
39+
change: this.onChange,
40+
keyup: this.onKeyup,
41+
keydown: this.onKeydown
42+
}
43+
})
44+
);
45+
46+
// add the error element
47+
children.push(
48+
h('error-display', {
49+
props: {
50+
form: this.form,
51+
field: this.field.key
52+
}
53+
})
54+
);
55+
return h('div', {
56+
'class': [
57+
'form-group formly-input',
58+
this.to.inputType,
59+
this.to.wrapperClasses,
60+
{
61+
'formly-has-value': this.model[ this.field.key ],
62+
'formly-has-focus': this.form[ this.field.key ].$active,
63+
'has-error has-danger': this.hasError
64+
}
65+
]
66+
}, children);
67+
},
68+
mixins: [baseField],
69+
methods: {
70+
onChange: function(e){
71+
72+
this.$set(this.form[this.field.key], '$dirty', true);
73+
this.runFunction('onChange', e);
74+
if ( this.to.inputType == 'file' ){
75+
this.$set(this.model, this.field.key, this.$el.querySelector('input').files);
76+
}
77+
78+
}
79+
}
80+
}

src/index.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
let Fields = require.context("./fields/", false, /^\.\/field([\w-_]+)\.vue$/);
1+
let Fields = require.context("./fields/", false, /^\.\/field([\w-_]+)\.js$/);
22
let FormlyBootstrap = {
3-
install(Vue, options){
4-
Fields.keys().forEach((key) => {
5-
//remove all the .vue crap
6-
let component = key
7-
.replace(/^\.\//, "")
8-
.replace(/\.vue/, "")
9-
.replace(/^field/, "");
10-
11-
//convert the first letter to lc
12-
component = component.charAt(0).toLowerCase() + component.slice(1);
3+
install(Vue, options){
4+
Fields.keys().forEach((key) => {
5+
//remove all the .vue crap
6+
let component = key
7+
.replace(/^\.\//, "")
8+
.replace(/\.js/, "")
9+
.replace(/^field/, "");
10+
//convert the first letter to lc
11+
component = component.charAt(0).toLowerCase() + component.slice(1);
1312

14-
Vue.$formly.addType(component, Fields(key));
15-
});
16-
}
13+
Vue.$formly.addType(component, Fields(key).default);
14+
});
15+
}
1716
};
1817

1918
//auto install
2019
if (typeof window !== 'undefined' && window.Vue) {
21-
window.Vue.use(FormlyBootstrap);
20+
window.Vue.use(FormlyBootstrap);
2221
}
2322

2423
export default FormlyBootstrap;

test/unit/specs/index.spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ function createForm(){
1717
//el.innerHTML = '<formly-form :form="form" :model="model" :fields="fields"></formly-form>';
1818
vm = new Vue({
1919
data: data,
20-
template: '<formly-form :form="form" :model="model" :fields="fields"></formly-form>'
20+
render(h){
21+
return h('formly-form', {
22+
props: {
23+
form: this.form,
24+
fields: this.fields,
25+
model: this.model
26+
}
27+
});
28+
}
2129
}).$mount(el);
2230

2331
return [el, vm];
@@ -226,7 +234,6 @@ describe('Bootstrap Field Inputs', () => {
226234
});
227235
});
228236

229-
230237
describe('conditional elements', ()=>{
231238
describeConditional('input');
232239
});
@@ -293,6 +300,8 @@ describe('Bootstrap Field Inputs', () => {
293300
});
294301

295302
});
303+
304+
return;
296305

297306
describe('Select', () => {
298307
describe('functions', ()=>{

0 commit comments

Comments
 (0)