Skip to content

Conversation

@ra-ph
Copy link

@ra-ph ra-ph commented Jul 29, 2020

Because it's evaluating 0 as false, so use hasOwnProperty instead

Currently I've set offsets that start at 0 to be 0.1 to get around it

error:
[Vue warn]: Invalid prop: custom validator check failed for prop "color".

ra-ph added 2 commits July 29, 2020 16:13
Because it's evaluating 0 as false, so use hasOwnProperty instead
@ra-ph ra-ph changed the title Bug: When offset is 0 Vue throws an error [Vue warn]: Invalid prop: custom validator check failed for prop "color". Jul 29, 2020
@setaman setaman self-requested a review July 29, 2020 19:45
if (typeof value === "object" && value.colors) {
return value.colors.every((config) => config.color && config.offset);
return value.colors.every((config) => {
let hasColor = Object.prototype.hasOwnProperty.call(config, "color");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gives true for { color: undefined, offset : ""}

@setaman
Copy link
Owner

setaman commented Jul 29, 2020

Hey, thanks for pointing this out. In my development environment i've always defined the value as String. This is why i have never seen this warning before. But actually offset must be defined as String, it can be a percent value as well. So it's more a doc mistake than an implementation bug. Because for { offset: "0" } the validator works fine. I will fix that in the upcoming v1.2.0 that will be released soon.

I close your PR, but thanks anyway 👍, otherwise I would never have noticed this error in the documentation!

Furthermore, your solution would also give true for { color: undefined, offset: "" }, that is incorrect since color and offset must have truthy values.

@setaman setaman closed this Jul 29, 2020
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

Successfully merging this pull request may close these issues.

2 participants