Lobos / react-ui

A collection of components for React, base on bootstrap 4.0.
http://lobos.github.io/react-ui/
MIT License
1.63k stars 302 forks source link

DatepickerRange数据验证逻辑错误 #116

Open xiaoxianjie opened 6 years ago

xiaoxianjie commented 6 years ago

<DatepickerRange type="date" min={custom_min} max={custom_max} name="daterange" unixtime={true} value={[custom_start, custom_end]} onChange={this.changeDaterange} />

./utils/validation.js 验证逻辑有问题 这里 valueType === "string" switch (valueType) { case 'array': len = toArray(value, sep).length break case 'number': len = parseFloat(value) break default: len = value.length break }

if (max && len > max) { return handleError(label, max, max.${valueType}, tip) } 如果形如 min = "2018-06-28",则下面验证可以绕过, 如果 形如 min = 1527643386974,则下面验证会进入报错 整个验证逻辑好像没有兼容到 DatepickerRange[type="date"] 模式 if (min && len < min) { return handleError(label, min, min.${valueType}, tip) }

Lobos commented 6 years ago

DatepickerRange 的 validate 走不到这里,应该调用的是这个文件 https://github.com/Lobos/react-ui/blob/master/src/Datepicker/Range.js

function validate (value = [], args) {
  if (!args.required) return true
  let result = (value[0] && value[1]) ? true
    : new Error(format(getLang('validation.tips.required'), args.label || ''))
  return result
}

export default compose(
  FormItem.register(['datetime-range', 'date-range', 'time-range'], { valueType: 'datetime', validate }),
  PureRender()
)(Range)