Skip to content

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

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

Closed
wants to merge 2 commits into from

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
@@ -7,7 +7,11 @@ const colorConfig = (defaultColor = "transparent") => ({
return true;
}
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