TypeError: Cannot read property 'slice' of null

8.6k views Asked by At

I am using autoform in my project and getting this error when I open the form Not sure if this is because of any versions or dependency, my autoform is not working and I am getting this error, I have the screenshot and the schema code, form code below,

enter image description here

template

<template name="assesmentNew">
  {{#ionModal customTemplate=true}}
    {{# autoForm collection="Assesments" id="assesments-new-form" type="insert"}}
      <div class="bar bar-header bar-stable">
        <button data-dismiss="modal" type="button" class="button button-clear">Cancel</button>
        <h2 class="title">New Assesment</h2>
        <button type="submit" class="button button-positive button-clear">Save</button>
      </div>
      <div class="content has-header overflow-scroll">
        {{> afQuickField name="name" }}
        {{> afQuickField name="email"}}
        {{> afQuickField name="category"}}
        {{> afQuickField name="location"}}
      </div>
    {{/autoForm}}
  {{/ionModal}}
</template>

Collection

Assesments = new Mongo.Collection('assesments');
Assesments.before.insert(function (userId, doc) {
  doc.createdAt = new Date();
});


Assesments.attachSchema(new SimpleSchema({
  name: {
   type: String,
    label: 'First Name',
    autoform: {
      'label-type': 'floating',
      placeholder: 'First Name'
    }
  },
  email: {
    type: String,
    label: 'Email',
    autoform: {
      'label-type': 'floating',
      placeholder: 'Email'
  }
  },
  category: {
    type: String,
      label: 'Category',
    optional: true,
    autoform: {
      options: [
        {value: 'General', label: 'General'},
        {value: 'Reported', label: 'Reported'},
        {value: 'Follow Up', label: 'Follow Up'}
      ],
      type: 'select-radio'
    }
  },
 assesmentDate: {
    type: Date,
    label: 'Assesment Date',
    optional: true
  },
  location: {
    type: String,
      label: 'Location',
      autoform: {
      'label-type': 'floating',
      placeholder: 'Location'
    },
    max: 200
  },
 createdBy: {
    type: String,
    autoValue: function() {
    return this.userId
  }
}
  }
    ));

if (Meteor.isServer) {
  Assesments.allow({ 
    insert: function (userId, doc) {
      return true;
    },
    update: function (userId, doc, fieldNames, modifier) {
      return true;
    },
    remove: function (userId, doc) {
      return true;
    }
  });
}
1

There are 1 answers

3
Rafael Quintanilha On BEST ANSWER

This is a issue with the new patch for autoform-ionic to the new versions of autoform.

Apparently some labels are skipped, some not (see here). In order to fix that and avoid this error when your input type is not there (for example, type = number), all your schema fields that are being rendered by autoform must have a label-type option defined:

...
autoform: {
   'label-type': 'placeholder',
   placeholder: 'Linha'
}