Skip to content

Adding a default value to selects #216

Closed
@stramel

Description

@stramel

I am creating a month select and need a default value of 'MONTH' which should be invalid. I have tried setting the model to a value that is declared in the titleMap but not the enum. Validation works as expected but I can't get a default value to show in the select. Is there something I am missing?

// Schema
scope.schema = {
  type: 'object',
  title: 'Payment Information',
  required: [
    'expirationDate'
  ],
  properties: {
    expirationDate: {
      title: 'Expiration Date',
      type: 'object',
      properties: {
        month: {
          title: 'Month',
          type: 'string',
          enum: monthsOfYear // Array of valid Months
        },
        year: {
          title: 'Year',
          type: 'string',
          enum: getValidCcYears() // Array of valid Years
        }
      }
    }
// Form
scope.form = [
  {
    key: 'expirationDate',
    notitle: true,
    items: [
      {
        key: 'expirationDate.month',
        type: 'select',
        titleMap: createTitleMap('MONTH', monthsOfYear), // Prepends 'MONTH'
        validationMessage: expirationMonthValidationMessages
      }, {
        key: 'expirationDate.year',
        type: 'select',
        titleMap: createTitleMap('YEAR', getValidCcYears()), // Prepends 'YEAR'
        validationMessage: expirationYearValidaitonMessages
      }
    ]
  }
// Model
scope.model = {
  expirationDate: {
    month: '?', // '?' is the key associated to the defaults
    year: '?' // '?' is the key associated to the defaults
  }
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions