Meteor Shaping Form Hidden Fields Not Showing Default, Not Saving
I have two hidden fields in my autoform schema as shown below. I want to keep these two fields with other fields without showing them to the application user. But I noticed from the autoform rendered html that the two hidden fields are irrelevant, nor do they persist with other fields in the DB. Not sure what I might be missing / wrong here? Thank you for your help.
Invoice = new SimpleSchema({
clientid: {
type: String,
optional: true
},
total: {
type: String,
label: 'Total Amount',
optional: true
},
tax: {
type: String,
label: 'Taxes',
optional: true
},
category: {
type: String,
optional: true,
autoform: {
type: "hidden",
label: false
},
defaultValue: 'Test Category'
}
});
{{> quickForm id="invoiceForm" buttonContent="Insert" buttonClasses="btn btn-primary btn-sm" schema=Invoice type="method" meteormethod="saveInvoice"}}
source to share
I don't think you can have a field in your alley schema that will display / receive on the form as a hidden field. So I suggest you pass the data (which you originally wanted to pass the hidden field) while the sessions.
For example, if you use autoform -> meteormethod to save the form, you can save the session content in a server method. If you are not using the method, you can pass hidden data via Autoform.hooks -> onSubmit
source to share
In my opinion, it is best to keep the form related logic with the template quickform
, for example if you reuse your schema in a different form.
I would recommend that you do the following:
...
},
category: {
type: String,
optional: true,
defaultValue: 'Test Category'
}
...
And use the suggestion omitFields
(note that you can specify multiple fields to skip by separating them with a comma):
{{> quickForm id="invoiceForm" buttonContent="Insert" buttonClasses="btn btn-primary btn-sm" schema=Invoice type="method" meteormethod="saveInvoice" omitFields="category, foo, bar, ..."}}
I noted that you are using method
as a form type. If you are manually configuring the method for saving your data, you might consider defining default values ββand automatically within the method itself. This will give you more freedom and control over your data.
source to share