Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Issue with createRecord in form component

$
0
0

@Chris_Stewart wrote:

Continuing the discussion from Question on autofocus for form field:

I am trying to do a createRecord based on form fields. As soon as I type in the form field I get errors in the console that state:

“Assertion Failed: Cannot call set with ‘srdescription’ on an undefined object.”

And when I submit the form I get the following error:

‘Cannot read property ‘createRecord’ of undefined’

I am guessing the component doesn’t know about the model maybe? If so how would I fix that?

Here is the create-form.hbs

 <form class="form-material m-t-40" onsubmit={{action "saveRequest"}}>
  <div class="form-group">
      <label>Description of Problem</label>
      {{textarea name='srdescription' value=model.srdescription class="form-control form-control-line" autofocus="true"}}
  </div>
    <div class="form-group">
        <label>Requester Name:</label>
        {{input type="text" class="form-control form-control-line" value=model.requester_name}}
   </div>
   <div class="form-group">
       <label>Requester Phone:</label>
       {{input type="text" class="form-control form-control-line" value=model.requester_phone}}
  </div>
 </form>

Here is the create-form.js

import Component from '@ember/component';

export default Component.extend({
  didInsertElement() {
    this._super(...arguments);
    this.$('[autofocus]').focus();
  },
  actions: {
    saveRequest(ev) {
      ev.preventDefault();
      let servicerequest = this.store.createRecord('servicerequest', this.model);
      servicerequest.save()
        .then (() => {
        this.transitionToRoute('servicerequest');
      });

    }
  }

});

In servicerequests.create hbs I call the component like this {{create-form}}

Any thoughts or suggestions are appreciated.

Posts: 11

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles