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 issue in Chrome #302

Closed
andlebed opened this issue Oct 25, 2016 · 2 comments
Closed

Validation issue in Chrome #302

andlebed opened this issue Oct 25, 2016 · 2 comments
Labels

Comments

@andlebed
Copy link

andlebed commented Oct 25, 2016

I'm submitting a bug report

  • Library Version:
    0.17.2
  • Aurelia-validation Version:
    0.13.1
  • Operating System:
    OSX 10.11.6
  • Node Version:
    6.7.0
  • NPM Version:
    3.10.8
  • Browser:
    Chrome 54.0.2840.71 (64-bit)
  • Language:
    ESNext

view-model.js

import {inject, NewInstance} from 'aurelia-framework';
import {ValidationController, ValidationRules} from 'aurelia-validation';
import {MaterializeFormValidationRenderer} from 'aurelia-materialize-bridge';

@inject(NewInstance.of(ValidationController))
export class ViewModel {

  email = '';
  isDisabled = false;

  constructor(controller) {
    this.controller = controller;
    this.controller.addRenderer(new MaterializeFormValidationRenderer());

    ValidationRules
      .ensure('email')
      .required().withMessage('We need your email')
      .email().withMessage('Wrong email')
      .on(this);
  }

  submit() {
    this.isDisabled = true;
  }

}

view.html

<template>
  <form submit.delegate="submit()">
    <md-input md-label="Email" md-value.bind="email & validate" md-disabled.bind="isDisabled" md-validate="true"></md-input>
    <button md-button="disabled.one-way: isDisabled; flat: true;">Send</button>
  </form>
</template>

Current behavior:
Type valid email into input, click "Send" button. Input contains "valid" in the class name.
screen shot 2016-10-25 at 03 09 18

Type valid email into input and press Enter. Input contains "invalid" in the class name.
screen shot 2016-10-25 at 03 09 35

Expected/desired behavior:
Input should remain valid after form submission by Enter.

Without md-validate="true" works fine.

@Thanood
Copy link
Collaborator

Thanood commented Oct 27, 2016

Hmm, this seems to happen because the input field doesn't lose focus on Enter (it doesn't blur?)..
In the catalog example you can even see the success message on top of the failure message.

image

Making the input field lose focus in any way (clicking outside the input field, switching browser tab) seems to trigger the correct validation.

The difference in the catalog sample is that the input has valid in its class name.
Strange.

@Thanood Thanood added the bug label Oct 27, 2016
@Thanood
Copy link
Collaborator

Thanood commented Jan 9, 2017

Tbh I think with aurelia-validation this is totally up to the user. That means if you configure blur as the validation trigger (it's the default) it won't trigger on change or keyup. Native input elements don't blur on enter, either..

However, I know from personal experience that such a blur-on-enter functionality can be very handy. I will add an additional option as a custom attribute md-blur-on-enter which does that. It will blur the input on enter and thus trigger validation (default is false to not break anything).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants