lundi 4 juin 2018

How to access the variable of a Route from a template in ember

I am trying to do form validation in ember using ember actions.

Below is my add.js(route):

    export default Route.extend({
    errorMessage: '',
    model() {
        return this.store.createRecord('contact');
    },
    actions: {
        saveContact(contact) {
            if (contact.get('firstname') === undefined || contact.get('lastName') === undefined || contact.get('mobile') === undefined) {
                this.set('errorMessage', `Some Fields are blank!!`);
            } else {
                this.set('hasBlank', false);
                this.set('errorMessage', "");
                contact.save().then(() => {
                    this.transitionTo("contacts")
                })
            }
        }
    }
});

This is my template code:

<h1>Add Contact</h1>
<div class="full-width">
    <div></div>
    <div></div>
    <div></div>
    <button class="form-button half-width" > Add </button>

     <div class="form-tag half-width"></div>

</div>

In this template errorMessage field is not showing when there is blank form fields.But it is showing up if I am logging it in my console.

Can Somebody help me out?



Thanks in Advance




Aucun commentaire:

Enregistrer un commentaire