Search code examples
meteormeteor-autoformmeteor-collection2

how to set a default value to element in a collection of type [String]?


i have quickform once the submit button clicked, this method is fired

submitPost: function (app) {
    check(app, {
      title: String,
      description: String,
      category: String,
      price: Number
    });
    var knownId = Products.insert(app);
    Products.update({ _id: knownId }, { $set:{screenShots: scs, previewImage: pi, sourceCode: zip }});

  }

the submit button wasn't working when i didn't give "screenShots, previewImage, and sourceCode" a default values in a collection.

Once i gave them a default value like it is shown below

previewImage: {
    type: String,
    defaultValue: "jjj",
  },
   sourceCode: {
    type: String,
    defaultValue: "jjj",
  },
  screenShots: {
    type: [String],
    autoValue: function() {
      return [];
    }
  },

now the submit button in the form is working and the update method is triggered. it updates both "previewImage and sourcCode" but "screenShots" is still empty.

am not sure but i believe the problem has to do with autoValue which i should make it a default value, but how do i give an element that of type array of string a default value?

or the problem has to do with something else?


Solution

  • use optional: true in the schema if the value is optional, and it will pass check if it is empty.