Meteor-Community-Packages / meteor-autoform

AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
MIT License
1.44k stars 328 forks source link

"MongoError: '$setOnInsert' is empty" when using more than one Boolean-type field in AutoForm #1657

Closed mishantidev closed 6 years ago

mishantidev commented 6 years ago

Getting an error in client console:

MongoError: '$setOnInsert' is empty. You must spec…y a field like so: {$setOnInsert: {: ...}}

I have two Boolean checkboxes in my form. If I remove one of them from the form, it works correctly ("animate" and "hasLink" fields).

Autoform 6.3.0, Meteor 1.6.1

Schema:

import { ElementImages } from './element_images.js'
import SimpleSchema from 'simpl-schema'

SimpleSchema.debug = true

SimpleSchema.extendOptions(['autoform'])
SimpleSchema.setDefaultMessages({
  initialLanguage: 'en',
  messages: {
    en: {
      uploadError: '{{value}}', //File-upload
    },
  }
})

export const Elements = new Mongo.Collection("Elements")

Elements.schema = new SimpleSchema({
  pageId: {
    type: String,
    label: 'Page Id',
    defaultValue: () => { return FlowRouter.current().route.name }
    // autoform: {
    //   type: 'select',
    //   // options() { return selectOptions(Pages) }
    // }
  },
  type: {
    type: String,
    label: 'Type',
    autoform: {
      options: {image: 'Image', imageSlider: 'Image Slider'}
    }    
  },
  width: {
    type: Number,
    label: 'Width, px',
    optional: true
  },
  height: {
    type: Number,
    label: 'Height, px',
    optional: true
  },
  imageId: {
    type: String,
    label: 'Image',
    optional: true,
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'ElementImages',
        // uploadTemplate: 'uploadField', // <- Optional
        // previewTemplate: 'uploadPreview' // <- Optional
      }
    }
  },
  hasLink: {
    type: Boolean,
    defaultValue: false,
    optional: true
  },
  linkAddr: {
    type: String,
    optional: true,
    label: 'Link address'
  },
  animate: {
    type: Boolean,
    defaultValue: true,
    optional: true
  },
  animationType: {
    type: String,
    label: 'Animation Type',
    optional: true,
    autoform: {
      type: 'select',
      options: {fadeIn: 'Fade in', slideInDown: 'Slide from top', slideInUp: 'Slide from bottom', slideInLeft: 'Slide from left', slideInRight: 'Slide from right'},
      defaultValue: 'fadeIn'
    }
  },
  animationDelay: {
    type: Number,
    label: 'Animation Delay, ms.',
    defaultValue: 0,
    optional: true
  }
})

Elements.attachSchema(Elements.schema)

Form:

        if Template.subscriptionsReady
            +autoForm collection=elementsCollection doc=element id="updateElementForm" type="update"

                fieldset
                    +afFormGroup name="type"

                if afFieldValueIs name="type" value="image"
                    fieldset
                        +afFieldInput name="imageId"

                fieldset
                    +afFieldInput name="hasLink"
                    if afFieldValueIs name="hasLink" value=true
                        +afFormGroup name="linkAddr"

                fieldset
                    +afFieldInput name="animate"
                    if afFieldValueIs name="animate" value=true
                        +afFormGroup name="animationType"
                        +afFormGroup name="animationDelay"

                input.button(type="submit" value="Save")

        else
            +spinner