I am using autoform to generate an "event" form. On the event I have a start date, start time, end date, end time. In the database I only want to store "start" and "end" which would be the dates and times combined. I can do this manually, but I'm having no luck doing it with autoform. How do I generate fields that are not part of my schema and have those go with the "doc" to my before submission hook? Is that the best way to do this? Right now I'm trying the following:
Schema:
start:
type: Date
label: 'Start'
end:
type: Date
label: 'End'
Template:
template(name='eventsNew')
+autoForm(collection='Events' id='insertEventForm' type='insert')
fieldset
legend Add an event
+afQuickField(name='type')
//- How do I output fields not in the schema and have them go to the form hooks? These output, but I can't get fields that are not part of the schema to work.
+afQuickField(name='start')
+afQuickField(name='end')
button.btn.btn-primary(type='submit') Submit
Form hook:
AutoForm.hooks
insertEventForm:
before:
insert: (doc)->
# Here is where I would think I could combine the times and dates
# but I can't get them to come through.
console.log doc
doc
I've tried afFieldInputs for the dates and times, but they don't generate anything. Not sure what I'm doing wrong. Thank you in advance for the help.
The addHooks options its only used when you want to apply the same hook to more that 1 form (an array
), on this example you are only using 1 form (insertEventForm
) so, the simple hook
will be work here.
I dont do Coffe Sorry
Simple JS
AutoForm.hooks({
insertEventForm:{
before:{
insert:function(doc){
console.log(doc) //do more stuff here
}
}
}
})