Skip to content

Validation not working without bindings from the Template #295

Description

@arggh

ViewModel validation seems to be usable only from the template by using VM bindings, like so:

Template.comp.viewmodel({
  field: ViewModel.property.string.notBlank
});
<span {{b "if: field.invalid"}}>your field has errors</span>

But this doesn't work:

Template.comp.viewmodel({
  field: ViewModel.property.string.notBlank
  hasErrors() {
    return this.field.invalid();
  }
});
{{#if hasErrors}}<span>your field has errors</span>

This makes it really hard to use ViewModel validation in components, for example, if I have a TextBox component that accepts hasErrors as a prop.

Reproduction: https://github.com/arggh/viewmodel-validation-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions