Use the same form to insert/update with Autoform

Meteor

Get the context data as usual. E.g. with iron-router, build a route like:

Router.route('Options',{
  path:'options',
  data:function(){var options =Options.findOne({owner:Meteor.userId()});return options;}});

 

Build a new helper, that checks if the context data (this in the helper) is empty or not (example is for a global helper that works in every template):

UI.registerHelper("formType",function(){if(_.isEmpty(this)){return'insert'}else{return'update';}});

Setup the template with the new helper:

<templatename="Options"><h1>Options</h1>
{{> quickForm collection="Options" doc=this id="optionsForm" type=formType omitFields="owner"}}
</template>

Credits:

http://stackoverflow.com/questions/25373859/how-to-use-the-same-form-for-updating-inserting-records-using-quickform