tbbooher / journal

0 stars 0 forks source link

update form currently won't commit #21

Closed tbbooher closed 9 years ago

tbbooher commented 9 years ago

we have this code to process the form:

entrySchema = ['entry_date',  'description',  'friends_in_focus',  'memory_verse',  'workout_done',  'purity',  'devotional',  'discipline',  'fitness',  'wife',  'relational',  'stress',  'flossed',  'sick',  'problem_solved',  'problem_attempted',  'lack_of_discipline',  'workout']

Template.entry_form.events 'submit #journal_entry_form': (event) ->
  event.preventDefault()
  entry = 'owner': Meteor.userId()
  # need to take care of created_at
  entry[field] = event.target[field].value for field in entrySchema
  dbUpsert = Entries.upsert "_id":@_id, entry
  event.target.reset() if dbUpsert.insertedId
  return

but this produces:

Uncaught Error: When the modifier option is true, all validation object keys must be operators. Did you forget `$set`?

what gives?

tbbooher commented 9 years ago

Can I reuse the same quickForm or autoForm for both inserts and updates?

Yes. Your code that flips between states should do the following in this order:

Change the type attribute's value to "insert" or "update" as appropriate, probably by updating a reactive variable. Change the doc attribute's value to the correct document for an update or to null (or a document containing default values) for an insert, probably by updating a reactive variable. Call AutoForm.resetForm(formId). This will clear any existing validation errors for the form.