Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatepickerRange数据验证逻辑错误 #116

Open
xiaoxianjie opened this issue Jun 28, 2018 · 1 comment
Open

DatepickerRange数据验证逻辑错误 #116

xiaoxianjie opened this issue Jun 28, 2018 · 1 comment

Comments

@xiaoxianjie
Copy link

<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
Copy link
Owner

Lobos commented Jul 3, 2018

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants