question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to validate one field without groups?

See original GitHub issue

For example I have class:

class ExampleModel extends Model {
    @MinLength(10)
    @IsAlphanumeric()
    public password: string;

    @IsEmail()
    @IsDefined()
    public email: string;
}

Can I validate only email or password, without validating other fields?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
ajitgaulicommented, Apr 19, 2018

@NoNameProvided I have a similar problem. From my UI, I need to call validate on blur and in this case I’d only want to validate the field I just blurred from. And blur from next field I’d want to validate that field only and so on. If only we could pass in property name or better yet the path to property (to handle nested objects) in ValidatorOptions, it would be possible to avoid unnecessary extra validations. As @Horat1us suggested, currently a way around to achieve this is to use groups but having 1 group per field just so that we can target it only is a lot of code bloat.

2reactions
LucienLeecommented, Feb 25, 2021

A workaround way is that you only pass one field and validate with skipMissingProperties option.

const exampleModel = new ExampleModel();
exampleModel.password = '123abc'

const errors = await validate(exampleModel, { skipMissingProperties: true })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Restrict data input by using validation rules - Microsoft Support
Create a field validation rule · Select the field that you want to validate. · On the Fields tab, in the Field Validation...
Read more >
Use Validation Groups for Buttons with Multiple Validation Rules
Present two buttons to the end user that, based on the selection, will validate only after a particular button is clicked. screenshot of...
Read more >
Validate the fields of a form - OutSystems 11 Documentation
Set the data types of the values in the form. You can do this manually or scaffold the form fields from Entity. Set...
Read more >
Bean Validation: Practical Examples from a Real- World Java ...
annotations placed on a field, method, or class of a JavaBeans component, ... We'll add another class “Course” to illustrate validating by group....
Read more >
Spring MVC Custom Validation - Baeldung
The isValid() method retrieves the values of the two fields and checks if they are equal. 9.3. Applying the Annotation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found