JosephusPaye / Keen-UI

A lightweight Vue.js UI library with a simple API, inspired by Google's Material Design.
https://josephuspaye.github.io/Keen-UI/
MIT License
4.1k stars 438 forks source link

Cannot apply regex validation #69

Closed EmilMoe closed 8 years ago

EmilMoe commented 8 years ago

I'm trying to apply regex validation to a UiTextbox, but it seems I'm missing something out from validatejs' documentation?

I have also tried :validation-rules but then it seems to just ignore it completely.

TypeError: Cannot read property 'apply' of undefined

<ui-textbox
    name="units"
    label="Units"
    validation-rules="['regex:/^((\d)*([,]){1}(\d){1,}$|^(\d*))$/']">
</ui-textbox>

What I want is to have a number input, but as it's in danish the decimal separator is not . but , (. is the thousand separator in danish). I don't know if it's supported in other ways than with this regex - would be really cool though.

JosephusPaye commented 8 years ago

I think the problem may be with the way we pass the validation-rules to validatorjs, since Vue expects the prop to be a string and using :validation-rules makes it an array.

Also the reason the string version doesn't work either is because of the pipe | character in the regex, which is used for separating rules when not using the array format.

I will change the validation-rules prop type to accept both String and Array and see if it solves the problem.

JosephusPaye commented 8 years ago

Implemented in https://github.com/JosephusPaye/Keen-UI/commit/fb14a9a10bd945eedb29d8d16d7b76e5f6cab0ce.

EmilMoe commented 8 years ago

Thanks. Do you know when 0.8.9 is going to be released?

JosephusPaye commented 8 years ago

Soon, there's only a few things left, mostly documentation. Perhaps next week if I find the time.

JosephusPaye commented 8 years ago

v0.8.9 has landed, which should fix the problem if you use an array.

JosephusPaye commented 7 years ago

In v1.0, validation has been removed from the components and should be performed externally. The error can be added to the components using the invalid and error props.