jeudi 22 décembre 2016

Ember.js 2.7 - How to check validation on an input field?

I'm pretty new to Ember.js and I'm having trouble how to do a validation on a certain input field.

Here is the code for my template index.hbs:

<div class="jumbotron text-center">
  <h1>Coming Soon</h1>

  <br/><br/>

  <p>Don't miss our launch date, request an invitation now.</p>

  <div class="form-horizontal form-group form-group-lg row">
    <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-1 col-md-5 col-md-offset-2">
      
    </div>
    <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">Request invitation</button>
    </div>
  </div>
  
    <div class="alert alert-success"></div>
  
  <br/><br/>
</div>

and here is the code from my controller index.js:

import Ember from 'ember';

export default Ember.Controller.extend({

  headerMessage: 'Coming soon',
  responseMessage: '',
  email: '',

  isValid: Ember.computed.match('email', /^.+@.+\..+$/),
  isDisabled: Ember.computed.not('isValid'),
});

The input field that I want to get validation for is the email one. I know how to go about the validation by replacing the value="" field to just value="email", but I want to know how I can do it using the value=model.email

This seems like an easy problem, but I can't find anything on the docs about this particular issue.




Aucun commentaire:

Enregistrer un commentaire