Search code examples
meteormeteor-autoformmeteor-collection2simple-schema

Meteor Autoform/SimpleSchema - quickform (type="update") not working


I have what I thought was a simple SimpleSchema with which I currently have two templates. One contains a quickform to insert a new document into the collection, the other is also a quickform which should update the document from the first template.

The insert form works fine, however when I try and load the update template, my console shows the following error and the submit button won't work. According to people who had similar problems, the error is normally caused by a recursive function, but I can't find one anywhere.

Exception from Tracker recompute function:
debug.js:41 RangeError: Maximum call stack size exceeded
    at Object (native)
    at isObject (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1000:18)
    at isBasicObject (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1024:10)
    at parseObj (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1147:15)
    at http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1159:11
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:159:22)
    at parseObj (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1155:9)
    at http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1159:11
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:159:22)
    at parseObj (http://localhost:3000/packages/aldeed_simple-schema.js?e210968641793751997ffe233af33b53af8566e4:1155:9)

Here are my two templates:

<template name="newWeddingPage1">
    <div class="  col-sm-10 col-sm-offset-1">
    <div class="  col-md-6">
        <div class="well well-sm">

        {{> quickForm collection="Weddings" id="insertWeddingInfo1" omitFields="email, phone, name, price" type="insert"}}

    </div>
    </div>

    <div class="  col-md-6">
        <div class="well well-sm">
        {{#each theweddingdetails}}
        <h1 id="price">{{duration}}</h1>
        {{/each}}


    </div>
    </div>



  </div>
</template>


<template name="newWeddingPage2">
    <div class="  col-sm-10 col-sm-offset-1">
    <div class="  col-md-6">
        <div class="well well-sm">
        {{#each theweddingdetails}} 
        {{> quickForm collection="Weddings" id="updateWeddingInfo1" doc="this" omitFields="email, phone, name, price" type="update"}}
        {{/each}}

    </div>
    </div>


  </div>
</template>

and my simple schema here:

Weddings.attachSchema(new SimpleSchema({

  address: {
    type: String,
    label: "Address",
    optional: true
  },
  startDate: {
    type: Date,
    label: "Date of shooting",
    optional: false,
  },
  startTime: {
    type: String,
    optional: true,
    autoform: {
      afFieldInput: {
        type: "time"
      }
    }
  },
  duration: {
    type: Number,
    label: "Duration (in hours)",
    optional: true
  },
  price: {
    type: Number,
    label: "Price",
    optional: true,
    autoform: {
      type: "hidden",
      label: false
    },
    autoValue:function(){ return 0 }
  },
  email: {
    type: String,
    optional: true,
    autoform: {
      afFieldInput: {
        type: "email"
      }
    }
  },
  phone: {
    type: Number,
    optional: true,
    autoform: {
      afFieldInput: {
        type: "tel"
      }
    }
  },
  name: {
    type: String,
    label: "Contact Person",
    optional: true
  },
  createdBy: {
    type: String,
    autoform: {
      type: "hidden",
      label: false
    },
    autoValue:function(){ return this.userId }
},
createdAt: {
    type: Date,
    autoform: {
      type: "hidden",
      label: false
    },
    autoValue:function(){ return new Date(); }
}
}));

Anybody have a clue where I'm going wrong?

Have been playing around with bits for the last few hours now :/


Solution

  • In your update form, you have doc="this" , which means you are just passing a string "this" as your doc.

    Try doc=this , without quotes. That way, you'll be passing the context variable this as your doc. I am assuming in your router or elsewhere you have passed the appropriate doc as your data context so that it will be available in this