mirror of https://github.com/ElemeFE/element
MessageBox: ensure to get input element
parent
4f00d7dea8
commit
37f4ce0b30
|
@ -216,7 +216,7 @@
|
||||||
var inputPattern = this.inputPattern;
|
var inputPattern = this.inputPattern;
|
||||||
if (inputPattern && !inputPattern.test(this.inputValue || '')) {
|
if (inputPattern && !inputPattern.test(this.inputValue || '')) {
|
||||||
this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
|
this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
|
||||||
addClass(this.$refs.input.$el.querySelector('input'), 'invalid');
|
addClass(this.getInputElement(), 'invalid');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var inputValidator = this.inputValidator;
|
var inputValidator = this.inputValidator;
|
||||||
|
@ -224,7 +224,7 @@
|
||||||
var validateResult = inputValidator(this.inputValue);
|
var validateResult = inputValidator(this.inputValue);
|
||||||
if (validateResult === false) {
|
if (validateResult === false) {
|
||||||
this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
|
this.editorErrorMessage = this.inputErrorMessage || t('el.messagebox.error');
|
||||||
addClass(this.$refs.input.$el.querySelector('input'), 'invalid');
|
addClass(this.getInputElement(), 'invalid');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (typeof validateResult === 'string') {
|
if (typeof validateResult === 'string') {
|
||||||
|
@ -234,13 +234,17 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.editorErrorMessage = '';
|
this.editorErrorMessage = '';
|
||||||
removeClass(this.$refs.input.$el.querySelector('input'), 'invalid');
|
removeClass(this.getInputElement(), 'invalid');
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
getFistFocus() {
|
getFistFocus() {
|
||||||
const $btns = this.$el.querySelector('.el-message-box__btns .el-button');
|
const $btns = this.$el.querySelector('.el-message-box__btns .el-button');
|
||||||
const $title = this.$el.querySelector('.el-message-box__btns .el-message-box__title');
|
const $title = this.$el.querySelector('.el-message-box__btns .el-message-box__title');
|
||||||
return $btns && $btns[0] || $title;
|
return $btns && $btns[0] || $title;
|
||||||
|
},
|
||||||
|
getInputElement() {
|
||||||
|
const inputRefs = this.$refs.input.$refs;
|
||||||
|
return inputRefs.input || inputRefs.textarea;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -266,19 +270,19 @@
|
||||||
}
|
}
|
||||||
this.focusAfterClosed = document.activeElement;
|
this.focusAfterClosed = document.activeElement;
|
||||||
messageBox = new Dialog(this.$el, this.focusAfterClosed, this.getFistFocus());
|
messageBox = new Dialog(this.$el, this.focusAfterClosed, this.getFistFocus());
|
||||||
};
|
}
|
||||||
|
|
||||||
// prompt
|
// prompt
|
||||||
if (this.$type !== 'prompt') return;
|
if (this.$type !== 'prompt') return;
|
||||||
if (val) {
|
if (val) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.$refs.input && this.$refs.input.$el) {
|
if (this.$refs.input && this.$refs.input.$el) {
|
||||||
this.$refs.input.$el.querySelector('input').focus();
|
this.getInputElement().focus();
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
} else {
|
} else {
|
||||||
this.editorErrorMessage = '';
|
this.editorErrorMessage = '';
|
||||||
removeClass(this.$refs.input.$el.querySelector('input'), 'invalid');
|
removeClass(this.getInputElement(), 'invalid');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue