Options should be an array of objects with at least one item in the array by default

Created on 18 January 2023, over 1 year ago

Problem/Motivation

When you query a webform in Gatsby graphql you must specify the options label and value.

The problem is that select field options can either be null or an array. We can't predict if the editor creating the webforms will add a select field or not so we always have to query options even though the form may or may not have a select field. GraphQL can't do conditions if a value is null or not.

In Drupal create a webform with just text fields

In gatsby query the webform you just created with the following:

export const query = graphql`
  query ($formId: String!) {
    webformWebform(drupal_internal__id: { eq: form_id_here }) {
      drupal_internal__id
      drupal_id
      title
      category
      description
      status
      elements {
        name
        type
        options {
          label
          value
        }
        attributes {
          name
          value
        }
      }
    }
  }
`;

Proposed resolution

By default add an array of options with even if the field is not a select field.

The gatsby-drupal-webform plugin builds select form fields off of the type 'select' so the options will be ignored.

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States AndySipple

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.69.0 2024