jeudi 20 juillet 2017

EmberJS - validating field from `Model` not works

I am trying to validate my email and message fields from model. but It seems that the validation not works as per expected.

my model :

import DS from 'ember-data';

export default DS.Model.extend({
    email: DS.attr('string'),
    message: DS.attr('string'),
    emailAddress:'',
    message:"",
    isValid :  Ember.computed.match('emailAddress', /^.+@.+\..+$/),
    isMessageValid : Ember.computed.gte('message.length', 5),
    isDisabled : Ember.computed.and("isValid", "isMessageValid")
});

my contact hbs file :

<h1>Contact</h1>
<div class="form-group has-success">
    <label class="control-label" for="inputSuccess1">Input Email</label>
    
    <label for="inpuitSucess2">Input Message</label>
    
    <br><br>
    <div class="col-xs-10 col-xs-offset-1 col-sm-offset-0 col-sm-4 col-md-3">
        <button disabled=""  class="btn btn-primary btn-lg btn-block">Send message</button>
    </div>
</div>


<div class="col-md-6">
    <br/>
    <div class="alert alert-success">
        <h4>Thank you! Your message is sent.</h4>
        <p></p>
    </div>
</div>


When I keep all this validation on controller it was worked well. when I move to model I am getting that validation fails.

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire