Merge branch 'main' into 2.x

pull/1740/head
贤心 2024-03-13 18:09:46 +08:00
commit 7472fecc14
4 changed files with 49 additions and 18 deletions

View File

@ -117,7 +117,7 @@ form 还可以借助*栅格*实现更灵活的响应式布局。
| lay-affix | [#详见](input.html#affix) | 输入框动态点缀,`<input type="text">`元素 **私有属性** |
| lay-skin | [#详见](checkbox.html#default) | 设置 UI 风格。 `<input type="checkbox">` 元素 **私有属性** |
| lay-search | 默认不区分大小写;<br>设置`cs`区分大小写 | 给 `select` 组件开启搜索功能。`<select>` 元素 **私有属性** |
| lay-creatable <sup>2.9.7+</sup> | 无需值 | 是否允许创建新条目,需要配合 `lay-search` 使用。`<select>` 元素 **私有属性** } |
| lay-creatable <sup>2.9.7+</sup> | 无需值 | 是否允许创建新条目,需要配合 `lay-search` 使用。`<select>` 元素 **私有属性** |
| lay-submit | 无需值 | 设置元素(一般为`<button>` 标签)触发 `submit` 提交事件 |
| lay-ignore | 无需值 | 设置表单元素忽略渲染,即让元素保留系统原始 UI 风格 |

View File

@ -61,6 +61,7 @@ layui.use(function(){
scrollbar: false, // 暂时屏蔽浏览器滚动条
anim: -1, // 禁用弹出动画
isOutAnim: false, // 禁用关闭动画
resize: false, // 禁用右下角拉伸尺寸
id: 'ID-layer-demo-inst',
skin: 'class-demo-layer-lockscreen', // className
content: ['<div class="layui-form">',
@ -167,4 +168,4 @@ layui.use(function(){
});
});
</script>
</script>

View File

@ -408,6 +408,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
// 搜索项
var laySearch = select.attr('lay-search');
// #1449
// IE10 和 11 中,带有占位符的 input 元素获得/失去焦点时,会触发 input 事件
// 当鼠标按下时,根据 input 元素上的 __ieph 标识忽略 input 事件
var needPlaceholderPatch = !!(lay.ie && (lay.ie === '10' || lay.ie === '11') && input.attr('placeholder'));
// 展开下拉
var showDown = function(){
@ -431,6 +436,15 @@ layui.define(['lay', 'layer', 'util'], function(exports){
}
followScroll();
if(needPlaceholderPatch){
dl.off('mousedown.select.ieph').on('mousedown.select.ieph', function(){
input[0].__ieph = true;
setTimeout(function(){
input[0].__ieph = false;
}, 60)
});
}
};
// 隐藏下拉
@ -582,9 +596,10 @@ layui.define(['lay', 'layer', 'util'], function(exports){
layui.each(dds, function(){
var othis = $(this);
var text = othis.text();
var isCreateOption = isCreatable && othis.hasClass(CREATE_OPTION);
// 需要区分大小写
if(isCreatable && text === rawValue){
if(isCreatable && !isCreateOption && text === rawValue){
hasEquals = true;
}
@ -598,7 +613,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
var not = text.indexOf(value) === -1;
if(value === '' || (origin === 'blur') ? value !== text : not) num++;
origin === 'keyup' && othis[(not && (isCreatable ? !othis.hasClass(CREATE_OPTION) : true)) ? 'addClass' : 'removeClass'](HIDE);
origin === 'keyup' && othis[(isCreatable ? (not && !isCreateOption) : not) ? 'addClass' : 'removeClass'](HIDE);
});
// 处理 select 分组元素
origin === 'keyup' && layui.each(dts, function(){
@ -623,6 +638,11 @@ layui.define(['lay', 'layer', 'util'], function(exports){
return false;
}
if(needPlaceholderPatch && e.target.__ieph){
e.target.__ieph = false;
return false;
}
notOption(value, function(none, hasEquals){
if(isCreatable){
if(hasEquals){
@ -661,12 +681,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
};
if(isSearch){
// #1449: IE10 和 11 中,带有占位符的 input 元素获得/失去焦点时,会触发 input 事件
var eventsType = 'input propertychange';
if(lay.ie && (lay.ie === '10' || lay.ie === '11') && input.attr('placeholder')){
eventsType = 'keyup';
}
input.on(eventsType, search).on('blur', function(e){
input.on('input propertychange', layui.debounce(search, 50)).on('blur', function(e){
var selectedIndex = select[0].selectedIndex;
thatInput = input; // 当前的 select 中的 input 元素

View File

@ -80,6 +80,17 @@ layui.define(['jquery', 'lay'], function(exports){
theme: '#16baaa' //主题颜色
};
// 数值精度
Class.prototype.precision = function(){
var that = this;
var options = that.config;
var precisions = $.map([options.min, options.max, options.step], function(v, i){
var decimalArr = String(v).split('.');
return decimalArr[1] ? decimalArr[1].length : 0;
})
return Math.max.apply(null, precisions);
}
//滑块渲染
Class.prototype.render = function(){
var that = this;
@ -99,8 +110,8 @@ layui.define(['jquery', 'lay'], function(exports){
// 合并 lay-options 属性上的配置信息
$.extend(options, lay.options(elem[0]));
//间隔值不能小于 1
if(options.step < 1) options.step = 1;
//间隔值不能小于等于 0
if(options.step <= 0) options.step = 1;
//最大值不能小于最小值
if(options.max < options.min) options.max = options.min + options.step;
@ -117,8 +128,8 @@ layui.define(['jquery', 'lay'], function(exports){
options.value[0] = Math.min(options.value[0],options.max);
options.value[1] = Math.min(options.value[1],options.max);
var scaleFir = Math.floor((options.value[0] - options.min) / (options.max - options.min) * 100);
var scaleSec = Math.floor((options.value[1] - options.min) / (options.max - options.min) * 100);
var scaleFir = (options.value[0] - options.min) / (options.max - options.min) * 100;
var scaleSec = (options.value[1] - options.min) / (options.max - options.min) * 100;
var scale = scaleSec - scaleFir + '%';
scaleFir = scaleFir + '%';
scaleSec = scaleSec + '%';
@ -132,7 +143,7 @@ layui.define(['jquery', 'lay'], function(exports){
if(options.value < options.min) options.value = options.min;
if(options.value > options.max) options.value = options.max;
var scale = Math.floor((options.value - options.min) / (options.max - options.min) * 100) + '%';
var scale = (options.value - options.min) / (options.max - options.min) * 100 + '%';
}
@ -281,7 +292,8 @@ layui.define(['jquery', 'lay'], function(exports){
var sliderWrap = sliderAct.find('.' + SLIDER_WRAP);
var sliderTxt = sliderAct.next('.' + SLIDER_INPUT);
var inputValue = sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').val();
var step = 100 / ((options.max - options.min) / Math.ceil(options.step));
var step = 100 / ((options.max - options.min) / options.step);
var precision = that.precision();
var change = function(offsetValue, index, from){
if(Math.ceil(offsetValue) * step > 100){
offsetValue = Math.ceil(offsetValue) * step
@ -309,7 +321,8 @@ layui.define(['jquery', 'lay'], function(exports){
}else{
sliderAct.find('.' + SLIDER_BAR).css({"width":wrapWidth + '%', "left":minLeft + '%'});
}
var selfValue = options.min + Math.round((options.max - options.min) * offsetValue / 100);
var selfValue = options.min + (options.max - options.min) * offsetValue / 100;
selfValue = Number(parseFloat(selfValue).toFixed(precision));
inputValue = selfValue;
sliderTxt.children('.' + SLIDER_INPUT_TXT).children('input').val(inputValue);
sliderWrap.eq(index).data('value', selfValue);
@ -366,7 +379,9 @@ layui.define(['jquery', 'lay'], function(exports){
};
//动态赋值
if(setValue === 'set') return change(value - options.min, i, 'done');
if(setValue === 'set'){
return change((value - options.min) / (options.max - options.min) * 100 / step, i, 'done');
}
//滑块滑动
sliderAct.find('.' + SLIDER_WRAP_BTN).each(function(index){