AutoForm with afFieldInput Does not submit

Hi Guys, I am really struggling with this one right here for like 48 hours no stop searching for the right answer. i have tried many solution but none really helped.

The problem is, that the Shema works fine and everything else, but when i click submit nothing really happen.

Please Please Guys I need help please.
Love,
Laurent,

{{#autoForm collection="Message" type="insert" scope="messages" class="form" id="sendMessage"}}
	   {{> afQuickField name="conversation_id" value=_id}}
	   <div class="row">
	   	<div class="input-field col s9 l8">
	   		{{> afFieldInput name="message"}}
	   	</div>
	   	<div class="input-field col s3 l4 right-align">
	   		<a type="submit" class="waves-effect waves-green btn btn-flat"><i class="material-icons green-text">send</i></a>
	   	</div>
	   </div>
	{{/autoForm}}

My Schema

import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);

Schema.Message = new SimpleSchema({
	conversation_id: {
		type: String,
		autoform: {
			type: 'hidden'
		}
	},
	'conversation_id.$': {
		type: String,
		autoform: {
			type: 'hidden'
		}
	},
	message: {
		type: String,
	},
	// ,
	// 'message.$': {
	// 	type: String,
	// },
	read: {
		type: Boolean,
		autoValue: function(){
			if(this.isInsert){
			   return false;
			}
		},
		autoform: {
			type: 'hidden'
		}
	},
	authorId: AutoValue.author,
	createdAt: AutoValue.now
});

Schema.Conversation = new SimpleSchema({
	users: {
		type: Array,
		optional: true,
	},
	'users.$': {
		type: String,
		optional: true,
	},
	read: {
		type: Array,
		optional: true,
	},
	'read.$': {
		type: String,
		optional: true,
	},
	createdAt: AutoValue.now,
	updatedAt: AutoValue.update
});

Message.attachSchema(Schema.Message);
Conversation.attachSchema(Schema.Conversation);
AutoValue = {
	now: {
		type: Date,
		autoValue: function (){
			if(this.isInsert){
				return new Date();
			}
			else if(this.isUpsert){
				return {$setOnInsert: new Date()};
			}
			else{
				this.unset();
			}
		},
		autoform: {
			type: 'hidden'
		},
		optional: true,
	},
	update: {
		type: Date,
		autoValue: function (){
			return new Date();
		},
		autoform: {
			type: 'hidden'
		},
		optional: true,
	},
	author: {
		type: String,
		autoValue: function() {
			if(this.isInsert){
				return this.userId;
			}
			else{
				this.unset();
			}
		},
		autoform: {
			type: 'hidden'
		},
		optional: true,
	},
};

It is hard to see the issue without the schema and the code you run in the submit event. Please add them, too.

1 Like

Hi @jkuester Thank you for the reply. I just updated my post.

Please help!

Okay there is your schema but still not the code on submit. In order to confirm it is basically working, please include the following code into your template (where the form is included):

  1. Please change the form type to normal:

{{# autoForm .... type="normal" ....}}

and add the following event to your Template events:

Template.someTemplate.events({
  'submit #sendMessage' (event, templateInstance) {
    event.preventDefault()
    const formValues = AutoForm.getFormValues('sendMessage')
    console.log(formValues)
  }
})

Please post the output of formValues here :slight_smile:

1 Like

Okay thank you so much. I will do. :heart: :blush:
You are the best.
As Iā€™m out at work. After work I will give that a try.

:heart:

Hi @jkuester :frowning: still doesnt work please help.

AutoForm.hooks({
      sendMessage: {
        onSubmit: function (insertDoc, updateDoc, currentDoc) {
      if (customHandler(insertDoc)) {
        this.done();
      } else {
      	console.log('Smth W.');
        this.done(new Error("Submission failed"));
      }
      return false;
    }
  }
});


Template.conversation.events({
  'submit #sendMessage' (event, templateInstance) {
    event.preventDefault()
    const formValues = AutoForm.getFormValues('sendMessage')
    console.log(formValues);
  }
})

@jkuester Thank you so much i solved it.

Changing the to

Working like charm. :slight_smile: