feat: 同步 longbow-select 组件代码与样式

This commit is contained in:
Argo Window10 2019-11-26 11:19:15 +08:00
parent 91b430aa9c
commit 7417c4909f
2 changed files with 22 additions and 7 deletions

View File

@ -50,6 +50,10 @@
cursor: not-allowed;
}
.form-select.is-disabled .form-select-append {
color: #c0c4cc;
}
.form-select-input {
color: #606266;
outline: none;

View File

@ -75,7 +75,7 @@
// 新控件 <div class="form-select">
this.$ctl = $(lgbSelect.Template).insertBefore(this.$element);
if ($input.attr('data-toggle') === 'lgbSelect') {
this.$input = $input.addClass("form-select-input").attr("aria-haspopup", "true").attr("aria-expanded", "false").attr("data-toggle", "dropdown");
this.$input = $input.addClass("form-select-input").attr("aria-haspopup", "true").attr("aria-expanded", "false").attr("data-toggle", "dropdown").attr("readonly", true);
}
else {
this.$input = $('<input type="text" readonly="readonly" class="form-control form-select-input" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"/>');
@ -114,11 +114,17 @@
// save attributes
var attrs = [];
["id", "data-default-val"].forEach(function (v, index) {
["id", "name", "class", "data-valid", "data-default-val"].forEach(function (v, index) {
var value = that.$element.attr(v);
if (value !== undefined) attrs.push({ name: v, value: value });
});
var disabled = this.$element.prop('disabled');
// set disabled property
if (disabled) {
this.disabled();
}
// replace element select -> input hidden
this.$element.remove();
this.$element = $('<input type="hidden" data-toggle="lgbSelect" />').val(that.val()).insertBefore(this.$input);
@ -139,12 +145,15 @@
this.$input.removeAttr('disabled');
};
_proto.reset = function (value) {
_proto.reset = function (value, init) {
var that = this;
// keep old value
var oldValue = this.$input.attr('value');
// default select value
if (init == undefined) init = true;
// warning: must use attr('value') method instead of val(). otherwise the others input html element will filled by first element value.
// see https://gitee.com/LongbowEnterprise/longbow-select/issues/IZ3BR?from=project-issue
this.$input.attr('value', '').removeClass('is-valid is-invalid');
@ -153,10 +162,12 @@
$.each(value, function (index) {
var $item = $('<a class="dropdown-item" href="#" data-val="' + this.value + '">' + this.text + '</a>');
that.$menus.append($item);
if (this.selected === true || this.value === oldValue || index === 0 || this.value === that.$element.attr('data-default-val')) {
that.$input.attr('value', this.text);
that.$element.val(this.value).attr('data-text', this.text);
$activeItem = $item;
if (init) {
if (this.selected === true || this.value === oldValue || index === 0 || this.value === that.$element.attr('data-default-val')) {
that.$input.attr('value', this.text);
that.$element.val(this.value).attr('data-text', this.text);
$activeItem = $item;
}
}
});
if ($activeItem !== null) $activeItem.addClass('active');