Skip to content

Commit

Permalink
feat(uni-app-x web): input、textarea maxlength逻辑调整
Browse files Browse the repository at this point in the history
1. 默认值调整为w3c规范一样,默认为不限制长度
2. 初始value值也受maxlength限制(w3c规范不受maxlength限制)
3. maxlength调整默认后,设置非法值时按默认值处理
4. 合法值是0和正整数。负数是非法值,按不限制对待。但正小数,是取整对待(不是四舍五入)
  • Loading branch information
Wangyaqi committed Mar 11, 2024
1 parent b4e01e5 commit 8305d30
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/uni-components/src/helpers/useField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ function useBase(
})
const maxlength = computed(() => {
var maxlength = Number(props.maxlength)
return isNaN(maxlength) ? 140 : maxlength
if (__X__) {
return isNaN(maxlength) || maxlength < 0
? Infinity
: Math.floor(maxlength)
} else {
return isNaN(maxlength) ? 140 : maxlength
}
})
const value =
getValueString(props.modelValue, props.type) ||
Expand All @@ -241,7 +247,10 @@ function useBase(
)
watch(
() => state.maxlength,
(val) => (state.value = state.value.slice(0, val))
(val) => (state.value = state.value.slice(0, val)),
{
immediate: __X__ ? true : false,
}
)
return {
fieldRef,
Expand Down

0 comments on commit 8305d30

Please sign in to comment.