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

Validation not working without bindings from the Template #295

Open
arggh opened this issue Sep 24, 2017 · 1 comment
Open

Validation not working without bindings from the Template #295

arggh opened this issue Sep 24, 2017 · 1 comment

Comments

@arggh
Copy link

arggh commented Sep 24, 2017

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

@ManuelDeLeon
Copy link
Owner

This seems to be an issue with the else if not VM, it works if you do something like:

{{#if isValidating}}
  <div>Validating</div> 
{{/if}} 
{{#if nameIsValid}}
  <div>Name is valid</div> 
{{/if}} 
{{#if nameIsInvalid}}
  <div>Name is not valid, minimum 5 chars</div> 
{{/if}}

If VM wasn't "reporting" the changes to Tracker the if's wouldn't update as necessary.

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

2 participants