Skip to content

Commit 5a22bd9

Browse files
committed
converting input field to v2.0
1 parent ba0a07e commit 5a22bd9

File tree

4 files changed

+427
-410
lines changed

4 files changed

+427
-410
lines changed

src/directives/index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@ export default function(Vue){
33
* Allows the user to pass extra attributes that should be added to the element. Such as placeholder etc etc
44
* @param {Object} value
55
*/
6-
Vue.directive('formly-atts', function(value){
7-
if ( typeof value == 'undefined' ) return;
8-
/*
9-
Object.keys(value).forEach((key) => {
10-
this.el.setAttribute(key, value[key]);
11-
});
12-
*/
6+
Vue.directive('formly-atts',{
7+
bind:function(el, binding){
8+
9+
if ( !binding.value ) return;
10+
11+
Object.keys(binding.value).forEach((key) => {
12+
el.setAttribute(key, value[key]);
13+
});
14+
15+
}
1316
});
17+
18+
19+
Vue.directive('formly-input-type', {
20+
bind: function(el, binding){
21+
if ( !binding.value ) return;
22+
23+
el.setAttribute('type', binding.value);
24+
}
25+
});
26+
1427
}

src/fields/baseField.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ export default
1818
if ( typeof this.to[action] == 'function' ) this.to[action].call(this, e);
1919
},
2020
onFocus: function(e){
21-
this.$set('form.'+this.field.key+'.$active', true);
21+
this.$set(this.form[this.field.key], '$active', true);
2222
this.runFunction('onFocus', e);
2323
},
2424
onBlur: function(e){
25-
this.$set('form.'+this.field.key+'.$dirty', true);
26-
this.$set('form.'+this.field.key+'.$active', false);
25+
this.$set(this.form[this.field.key], '$dirty', true);
26+
this.$set(this.form[this.field.key], '$active', false);
2727
this.runFunction('onBlur', e);
2828
},
2929
onClick: function(e){
3030
this.runFunction('onClick', e);
3131
},
3232
onChange: function(e){
33-
this.$set('form.'+this.field.key+'.$dirty', true);
33+
this.$set(this.form[this.field.key], '$dirty', true);
3434
this.runFunction('onChange', e);
3535
},
3636
onKeyup: function(e){

src/fields/fieldInput.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="form-group formly-input" :class="[ to.type, {'formly-has-value': model[field.key], 'formly-has-focus': form[field.key].$active}]">
33
<label v-if="to.label" :for="to.id ? to.id : null">{{to.label}}</label>
4-
<input class="form-control" :class="to.classes" :id="to.id ? to.id : null" :type="to.type || text" v-model="model[field.key]" @blur="onBlur" @focus="onFocus" @click="onClick" @change="onChange" @keyup="onKeyup" @keydown="onKeydown" v-formly-atts="to.atts">
4+
<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">
55
</div>
66
</template>
77

@@ -11,13 +11,13 @@
1111
mixins: [baseField],
1212
methods: {
1313
onChange: function(e){
14-
/*
15-
this.$set('form.'+this.key+'.$dirty', true);
14+
15+
this.$set(this.form[this.field.key], '$dirty', true);
1616
this.runFunction('onChange', e);
17-
if ( this.form[this.key].inputType == 'file' ){
18-
this.$set('form.'+this.key+'.files', this.$el.querySelector('input').files);
17+
if ( this.to.type == 'file' ){
18+
this.$set(this.model, this.field.key, this.$el.querySelector('input').files);
1919
}
20-
*/
20+
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)