mardi 7 juin 2016

Set model date defaultValue to string

I try to build a 'task manager' to log the tasks that my customers send me.

I have my new-task.hbs form

<div id="new-task-form" class="col-md-12">
<form>
    <div class="form-group">
        <label>Customer</label>
        
    </div>

    <div class="form-group">
        <label>Task</label>
        
    </div>

    <div class="form-group">
        <label>Incoming</label>
        
    </div>
    <div class="form-group">
        <label>Pending</label>
        
    </div>

    <div class="form-group">
        <label>Closed Date</label>
        
    </div>

    <button  class="btn btn-primary">Submit</button> 
</form>

My controller.

    import Ember from 'ember';

export default Ember.Controller.extend({
    actions: {
        addTask: function(){
            var customer = this.get('customer');
            var task = this.get('task');
            var incoming = this.get('incoming');
            var pending = this.get('pending');
            var closed_date = this.get('closed_date');
            //Create new task
            var newTask = this.store.createRecord('task',{
                customer: customer,
                task: task,
                incoming: incoming,
                pending: pending,
                closed_date: closed_date
            });
            //save to db
            newTask.save();
        }
    }
});

And the model

import Model from 'ember-data/model';
import attr from 'ember-data/attr';

export default Model.extend({
  customer: attr('string'),
  task: attr('string'),
  incoming: attr('number', { defaultValue: 0 }),
  pending: attr('number', { defaultValue: 0 }),
  closed_date: attr('date'),
  created: attr('string', {
    defaultValue: function(){
        return new Date();
    }
  })  
});

How can i set a model defaultValue for a the closed_date input to a string "Not entered yet"?

If i leave it like this and not enter a value i get an "Invalid Date".

closed_date: attr('date')

If i set this i get the current date.

closed_date: attr('date', { defaultValue: 'Not entered yet' })




Aucun commentaire:

Enregistrer un commentaire