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

resetOnSuccess=false not working #1680

Closed nosizejosh closed 5 years ago

nosizejosh commented 5 years ago

@aldeed does resetOnSuccess=false work on latest version of autoform(6.3.0)? I have similar requirements to keep an update form from resetting after submission but attempts to use this method doenst work.

// ui code

{{#if currentEvent}}        
    {{#autoForm collection=AutoFormCollections.Events id="aboutEventUpsertForm" doc=currentEvent type='method-update' meteormethod="events.modifier.update" resetOnSuccess=false}}
        {{> eventAboutFormPartial}}
    {{/autoForm}}  

{{else}}
    {{#autoForm collection=AutoFormCollections.Events id="aboutEventUpsertForm" doc=currentEvent type='method' meteormethod="events.insert"}}
        {{> eventAboutFormPartial}}
    {{/autoForm}}
{{/if}} 

// template code

AutoForm.hooks({
  aboutEventUpsertForm :{  //insert update (upsert) form https://forums.meteor.com/t/upsert-in-autoform/7161/6?u=nosizejosh
      onSubmit: function (insertDoc, updateDoc, currentDoc) {
      this.event.preventDefault();  
        return false;
      },
      onSuccess: function(formType, result) {
        // set resulting newly created eventid to the currentEventId to aid in uspert form creation
        // console.log(result);
        CurrentEventId.set(result); 
        Bert.alert({
            title: 'Registration Success',
            message: 'Charter Registration Successfull!',
            type: 'success',
            style: 'growl-top-right',
            icon: 'fa-money'
        });
        // trying to prevent update form from refreshing after successful update
        this.event.preventDefault();
        return false;
      },
      onError: function(formType, error) {
      // must check if for specific error before calling bert, else bert will always be called for any onError
        Bert.alert({
          title: error.error,
          message: error.message,
          type: 'danger',
          style: 'growl-top-right',
          icon: 'fa-frown-o',
          hideDelay: 5000,
        });
  },
}
});

anyone with knowledge on this please help.

nosizejosh commented 5 years ago

thank you but i found it actually works. my challenge was from this line

CurrentEventId.set(result); after update, result was undefined and hence it was setting reactive var to undefined.

Thanks