mardi 4 juillet 2017

EmberJS - how to access model values in `Controller`

I am trying to validate 2 input field in view. for that, I am trying to access my model values. But I am not get any success on this.

what is the correct to access the model from controller ?

here is my try :

import Ember from 'ember';

export default Ember.Controller.extend({

    model( ){
        this.store.createRecord('contact') 
    },
    data: Ember.computed.alias('model'),//i am setting alias..!?
    isValidEmail : Ember.computed.match('data.emailAddress', /^.+@.+\..+$/),
    isMessageEnoughLong : Ember.computed.gte('data.message.length', 5),
    isValid : Ember.computed.and('isValidEmail', 'isMessageEnoughLong'),//not works!!
    actions:{
        sendMessage: function( newContact ) {

            console.log("new contact is", newContact );
            return;
            var email = this.get('data.emailAddress');
            var message = this.get('data.message');

            alert('Sending your message in progress... ');

            var responseMessage = 'To: ' + email + ', Message: ' + message;
            this.set('responseMessage', responseMessage);
            this.set('emailAddress', '');
            this.set('message', '');
        }
    }
});

Here is my HTML :

<div class="col-md-6">
        <div class="form-group">
            <label>Your email address*:</label>
            
        </div>
        <div class="form-group">
            <label>Your message*:</label>
            
        </div>
        <button class="btn btn-success"  disabled="">Send</button>
    </div>




Aucun commentaire:

Enregistrer un commentaire