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

onSubmit Hook doesn't work with #autoForm #1647

Closed gmartinezETRA closed 6 years ago

gmartinezETRA commented 6 years ago

Hello everybody.

After been some days reading possible solutions for my problem (solutions that probably worked in the past), I have finally decided to post it to see if somebody can help me with it.

Once again, I am dealing with the "non-woking onSubmit" problem. I have the following autoForm code on my "program.html":

<template name="processesform">
    <div class="ui small modal" id="dlg_new_process">
        <i class="close icon"></i>
        <div class="header">
            {{_"New tariff"}}
        </div>
        <div class="content">
            {{#autoForm schema=newProcessFormSchema id="newProcessForm" type="normal" collection="Collections.Tariffs"}}
            <fieldset>
                {{> afQuickField name="name"}} 
                {{> afQuickField name="site"}} 
                {{> afQuickField name="country"}}
            </fieldset>
            <div class="ui hidden divider"></div>
            <div class="ui buttons">
                <button type="button" class="ui cancel button">{{_ "Cancel"}}</button>
                <div class="or" data-text="{{_ " Or "}}"></div>
                <i class="save icon"></i>
                <button type="submit" class="ui positive button">{{_ "Insert"}}</button>
            </div>
            {{/autoForm}}
        </div>
    </div>
</template>

On my "program.js" I have this Hook:

AutoForm.hooks({
  newProcessForm: {
    onSubmit: function(insertDoc, updateDoc, currentDoc) {
      this.event.preventDefault()
      console.log("submited")
      this.done()
      return false
    },
  }
});

When I click on "Insert" button, the "submitted" message is not displayed on the console.

Thanks for your time :)