-1

I want to know when the textbox is empty and when user click the submit button the error message will need to show. Please help me.

This is my template register.hbs code

      {{paper-input
        label="E-mail"
        type="email"
        value=email
        onChange=(action (mut email))
        icon="email"
      }}

  {{#paper-button raised=true primary=true onClick=(action "register")}}Register{{/paper-button}}

and this is my controller register.js code

email: null,


actions: {
  register() {
    var data = {
      email: this.get('email'),
    };
    var record = this.store.createRecord('register', data);
    record.save().then((response) => {
      this.set('email', null);
      this.transitionToRoute('activation');
    });
  }
}
Girja Shanker
  • 85
  • 1
  • 10
  • Please take a look at http://offirgolan.github.io/ember-cp-validations/docs/modules/Usage.html. This is the best. And take a look at http://miguelcobain.github.io/ember-paper/release-1/#/components/input for using cp-validations in ember-paper – Ebrahim Pasbani Feb 20 '17 at 14:54

1 Answers1

1

Just put something like:

if (!this.get('email').trim()){
  //your code to show some error message
  return
}

trim() removes possible whitespaces from the mail and a empty or null string is falsy in javascript:

More on trim

More on what evaluates to True/False for strings

Community
  • 1
  • 1
Maurice Döpke
  • 367
  • 3
  • 9