Search code examples
meteormeteor-autoform

How can I pre-select a value from a dropdown list with meteor and autoform?


I'm using autoform with simple-schema and trying to pre-select a value from a dropdown list. I either crash the app or get no notice, no result, nothing. The selected value still shows (Select One). Here's the block from my schema:

status:{
  type: String,
  label: "Status",
  allowedValues: ['Approved','Pending','Flagged'],
  autoValue: function() {
    return {label: 'Pending', value: 'Pending'};
  }
},

Solution

  • Taken from the documentation: https://github.com/aldeed/meteor-autoform#affieldinput

    To specify a label to be displayed when there is no option selected, set firstOption="(My Select One Label)".

    firstOption: Use with the options attribute to specify a string to use for the first option of a select input, which shows when nothing has been selected yet. For example, firstOption="(You Should Really Pick Something From This List)". There is a default first option "(Select One)". If you don't want any default option, then do firstOption=false, but make sure your select input has a default value or this will result in a confusing UX where it looks like the first option is selected but it isn't.