How to show the error message when the textbox is empty when user click the submit button in ember.js?

202 Views Asked by At

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');
    });
  }
}
1

There are 1 best solutions below

0
Maurice Döpke On BEST ANSWER

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