mongodb - Using same form for insert and edit -


how can use same form inserting , editing document in meteor.

for insert use empty form without variable:

<template name="frmorganization">    // no doc variable    <form class="form-horizontal" role="form">      ...      <input type="text" class="form-control" id="name"> 

and update use form variable:

<template name="frmorganization">    {{#with organization}} // doc variable    <form class="form-horizontal" role="form">      ...      <input type="text" class="form-control" id="name" value="{{name}}"> 

(using meteor 0.9.3 + iron-router)

i had same issue , workaround used follows (seems more of hack avoid having multiple forms)

<template name="frmorganization"> // no doc variable <form class="form-horizontal" role="form">   ...   <input type="text" class="form-control" id="name" value={{name}}>   {{#if name}}     <input type="submit" value="edit"/>     <input type="submit" value="delete"/>   {{else}}     <input type="submit" value="add"/>   {{/if}}   ... 

in router.js file

this.route('frmorganization', {   path: '/organisation/:_id/edit',   data: function() { return organisation.findone(this.params._id); } }); 

all seems pretty standard, add link, use:

<a href="{{pathfor 'frmorganization' _id=new}}">add</a> 

which create following link:

/organisation/null/edit 

the null page gives add page , id give edit page.

-- meteor noob


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -