2018-06-27 14:38:27 +00:00
|
|
|
<script>
|
|
|
|
import Base from './Base';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
extends: Base,
|
|
|
|
computed: {
|
|
|
|
inputClass() {
|
|
|
|
return ['d-none'];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getWrapperElement(h) {
|
2018-07-14 11:39:42 +00:00
|
|
|
let fileName = this._('Choose a file..');
|
2018-06-27 14:38:27 +00:00
|
|
|
|
|
|
|
if (this.$refs.input && this.$refs.input.files.length) {
|
|
|
|
fileName = this.$refs.input.files[0].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileButton = h('button', {
|
|
|
|
class: ['btn btn-outline-secondary btn-block'],
|
|
|
|
domProps: {
|
|
|
|
textContent: fileName
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
click: () => this.$refs.input.click()
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return h('div', {
|
2018-07-14 11:39:42 +00:00
|
|
|
class: ['form-group', ...this.wrapperClass],
|
|
|
|
attrs: {
|
2018-06-27 14:38:27 +00:00
|
|
|
'data-fieldname': this.docfield.fieldname
|
2018-07-14 11:39:42 +00:00
|
|
|
}
|
|
|
|
}, [this.getLabelElement(h), this.getInputElement(h), fileButton]);
|
2018-06-27 14:38:27 +00:00
|
|
|
},
|
|
|
|
getInputAttrs() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
type: 'file',
|
|
|
|
value: this.value,
|
2018-07-12 11:29:10 +00:00
|
|
|
required: this.docfield.required,
|
2018-07-14 11:39:42 +00:00
|
|
|
disabled: this.disabled,
|
|
|
|
webkitdirectory: this.docfield.directory,
|
|
|
|
directory: this.docfield.directory
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getInputListeners() {
|
|
|
|
return {
|
|
|
|
change: e => {
|
|
|
|
this.handleChange(e.target.files);
|
|
|
|
}
|
|
|
|
};
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-14 11:39:42 +00:00
|
|
|
};
|
2018-06-27 14:38:27 +00:00
|
|
|
</script>
|