1

The example i'm goint o use here is taken from http://autoform.meteor.com/quickform

I've been using autoform for a few projects, but i need to get this same behaviour without it, how could i do an insert of an Array of objects??

So here is the Schema definition you need with autoform

 items: {
  type: Array,
  optional: true,
  minCount: 0,
  maxCount: 5
 },
   "items.$": {
      type: Object
   },
   "items.$.name": {
      type: String
   },
   "items.$.quantity": {
      type: Number
   }

Next is the call to autoform to generete the form in the template

{{> quickForm id="demo" schema=schemaFromJSON type="method" meteormethod="demoSubmission"}}

With that in place you get a form, displaying both fields: name and quantity, plus a sign for ading more objects with those same fields, and when you actually submit the form it inserts all of your objects.

The HTML and CSS is not the problem

1 Answer 1

1

I'm not quite sure what you are asking. These are two ways of inserting arrays to collection:

// insert items one by one
// NOTE: Meteor doesn't allow inserting of arrays like `Items.insert(items)`
items.forEach(item => Items.insert(item));

// insert all items simultaneously by using raw mongo collection:
Items.rawCollection().insert(items);
Sign up to request clarification or add additional context in comments.

1 Comment

ok, sorry if was not clear. I want to know how could I englobe all my objects when i want to insert the form. You know that before inserting any input field you grab it, like doing something like this $('[name="something"]), and then you can insert it. But since here i'm introducing a <fieldset> with 2 inputs on each fieldset, how do i grab them?? i've read in Meteor in Action about a solution but they are using a local collection with the array in it, then they let a Meteor helper update the DOM as you push arrays into it, and then they pass that local document into the DB. I don't want Local

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.