Search code examples
meteormeteor-autoform

Meteor autoform Form hidden fields not rendering defaultValue and not saving


I have two hidden fields in my autoform Schema defined as shown below. I wish to save those two fields with other fields while not showing them to the app user. But I noticed from the autoform rendered html that the two hidden fields have no value, also they don't save with other fields to DB. Not sure what I might be missing / wrong here? Thanks 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"}}

Solution

  • I don't think that you can have a field in your aldeed Schema that will render/ get saved in the form as a hidden field. So I suggest you pass the data (which you originally wanted to pass a a hidden field) though Sessions.

    For example, if you are using autoform >> meteormethod to save the form, then you can save the session content within the server method. If you are not using a method, then you might want to pass the hidden data through Autoform.hooks >> onSubmit