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

Add support to validate nested objects #333

Open
villander opened this issue Oct 1, 2023 · 0 comments
Open

Add support to validate nested objects #333

villander opened this issue Oct 1, 2023 · 0 comments

Comments

@villander
Copy link

villander commented Oct 1, 2023

We'd like to have the ability to copy the model and apply validations without creating N @tracked properties to every model field we want to validate into the component.

import Model, { attr } from '@ember-data/model';

export default class MyModel extends Model {
  @attr('string') details;
  @attr('string') name;
  @attr('string') color;
}
import Component from '@ember/component';
import { objectValidator } from 'ember-model-validator';

@objectValidator
export default class MyComponent extends Component {
  @tracked formData;

  constructor(
    owner: unknown,
    args: CompSignature['Args'],
  ) {
    super(owner, args);

    this.formData = this.args.model;
  }
  
 validations = {
    formData: { 
      details: { presence: true },
    }
 };
  
}
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

No branches or pull requests

1 participant