Reputation: 85
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');
});
}
}
Upvotes: -1
Views: 199
Reputation: 367
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 what evaluates to True/False for strings
Upvotes: 1