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

Question: Validate against sub-schema? #807

Closed
cdaringe opened this issue Jan 21, 2016 · 4 comments
Closed

Question: Validate against sub-schema? #807

cdaringe opened this issue Jan 21, 2016 · 4 comments
Assignees
Labels
feature New functionality or improvement support Questions, discussions, and general support
Milestone

Comments

@cdaringe
Copy link

Hello:

I have a schema, but when my user is using a form, I want to validate onkeypress only the particular field they've modified, using the overarching schema that the form already composes.

// purely hypothetical, but 
var schema = { a: joi.string(), b: joi.string() };
onkeypress = function(evt) {
    joi.validate(evt.target.value, schema.a); // where i could extract a's schema rules only
}

is such a feature available?

@cdaringe
Copy link
Author

i did end up var childSchemasByName = _.indexBy(schema._inner.children, 'key');, but that's probably taboo :/

@Marsup
Copy link
Collaborator

Marsup commented Jan 21, 2016

You can also see it the other way, your schema is composed of many sub-schemas, why not compose them afterwards.

@cdaringe
Copy link
Author

thanks for the great tip, @Marsup. unfortunately, I don't directly own the code i'm pulling from. for now, what I've done does the trick. perhaps joi would be open to a joi.subschema(schema, 'path.to.subschema'), which would wrap that which I proposed above?

@Marsup Marsup added the support Questions, discussions, and general support label Feb 2, 2016
@Marsup Marsup self-assigned this Feb 2, 2016
@Marsup Marsup added this to the 7.3.0 milestone Feb 9, 2016
@Marsup Marsup added the request label Feb 9, 2016
@Marsup Marsup closed this as completed in ba0e808 Feb 11, 2016
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants