1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 20:39:48 +08:00

feat: Add autofocus and showControl attributes. (#478)

This commit is contained in:
Edwin Betancourt 2020-05-01 18:00:05 -04:00 committed by GitHub
parent 8e00a50b14
commit 098de4d8f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 4 deletions

View File

@ -38,7 +38,9 @@ export const fieldMixin = {
},
methods: {
activeFocus() {
this.$refs[this.metadata.columnName].focus()
if (this.$refs[this.metadata.columnName]) {
this.$refs[this.metadata.columnName].focus()
}
},
/**
* Overwrite component method if necessary
@ -49,6 +51,14 @@ export const fieldMixin = {
this.handleChange(value)
},
focusGained(value) {
if (this.metadata.isAutoSelection) {
// select all the content inside the text box
if (!this.isEmptyValue(value.target.selectionStart) &&
!this.isEmptyValue(value.target.selectionStart)) {
value.target.selectionStart = 0
value.target.selectionEnd = value.target.value.length
}
}
if (this.metadata.handleFocusGained) {
this.$store.dispatch('notifyFocusGained', {
containerUuid: this.metadata.containerUuid,

View File

@ -9,7 +9,8 @@
:placeholder="metadata.help"
:disabled="isDisabled"
:precision="precision"
controls-position="right"
:controls="isShowControls"
:controls-position="controlsPosition"
:class="'display-type-amount ' + metadata.cssClassName"
@change="preHandleChange"
@blur="focusLost"
@ -62,6 +63,24 @@ export default {
return 2
}
return undefined
},
isShowControls() {
if (!this.isEmptyValue(this.metadata.showControl)) {
if (this.metadata.showControl === 0) {
return false
}
}
return true
},
controlsPosition() {
if (!this.isEmptyValue(this.metadata.showControl)) {
// show side controls
if (this.metadata.showControl === 1) {
return undefined
}
}
// show right controls
return 'right'
}
},
watch: {

View File

@ -89,6 +89,6 @@ export default {
<style>
.custom-field-yes-no {
min-height: 34px;
max-height: 34px;
}
</style>

View File

@ -6,6 +6,7 @@ export default [
columnName: 'URL',
definition: {
name: 'Web',
isAutoSelection: true,
displayType: URL.id
}
},
@ -69,7 +70,8 @@ export default [
definition: {
name: 'Sequence for record',
displayType: INTEGER.id,
mandatoryLogic: '@URL@!""'
mandatoryLogic: '@URL@!""',
showControl: 1
}
},
// Text Long