Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG? Field label required for validation message to be displayed #302

Open
cvalarida opened this issue Oct 19, 2018 · 0 comments
Open

BUG? Field label required for validation message to be displayed #302

cvalarida opened this issue Oct 19, 2018 · 0 comments
Labels
[practice] engineering Engineering related work

Comments

@cvalarida
Copy link
Contributor

cvalarida commented Oct 19, 2018

I'm not sure this qualifies as a bug exactly, but it seemed fitting enough. It seems like a bug that I can accidentally hide the validation messages.

Describe the bug
The field label is required to show validation messages, which means we have to employ some odd workarounds at times. For example, let's say we want to make the following:

image

We could do something like:

uiSchema:
  'view:uploadPrivateRecords': {
    'ui:title':
      'Do you want to upload your private medical records?',
    'ui:widget': 'radio',
    'ui:options': {
      labels: {
        yes: 'Yes',
        no: 'No, please get them from my doctor',
      },
    },
  },
  'view:patientAcknowledgement': {
    'ui:options': {
      expandUnder: 'view:uploadPrivateRecords',
      expandUnderCondition: 'no',
    },
  },
  'view:patientAcknowledgementDescription': {
    'ui:description': patientAcknowledgmentText
  },
},
schema: {
  type: 'object',
  required: ['view:uploadPrivateRecords'],
  properties: {
    'view:uploadPrivateRecords': {
      type: 'string',
      enum: ['yes', 'no'],
    },
    'view:patientAcknowledgement': {
      type: 'object',
      required: ['view:acknowledgement'],
      properties: {
        'view:acknowledgement': {
          type: 'boolean',
          default: true,
        },
      },
    },
    'view:patientAcknowledgementDescription': {
      type: 'object',
      properties: {},
  },
}

But when the check box isn't checked and the validation is triggered, the validation message doesn't appear on the screen. This is because the check box--the field that triggered the validation--doesn't have a title for the message to "hook" onto. We then have to change it up and add an "empty" title, which creates the awkward space between the radio button and check box in the screenshot above.

uiSchema:
  'view:uploadPrivateRecords': {
    'ui:title':
      'Do you want to upload your private medical records?',
    'ui:widget': 'radio',
    'ui:options': {
      labels: {
        yes: 'Yes',
        no: 'No, please get them from my doctor',
      },
    },
  },
  'view:patientAcknowledgement': {
    'ui:title': ' ',
    'ui:help': patientAcknowledgmentText,
    'ui:options': {
      expandUnder: 'view:uploadPrivateRecords',
      expandUnderCondition: 'no',
      showFieldLabel: true,
    },
  }
},
schema: {
  type: 'object',
  required: ['view:uploadPrivateRecords'],
  properties: {
    'view:patientAcknowledgement': {
      type: 'object',
      required: ['view:acknowledgement'],
      properties: {
        'view:acknowledgement': {
          type: 'boolean',
          default: true,
        },
      },
    },
    'view:privateRecordsChoiceHelp': {
      type: 'object',
      properties: {},
    },
  },
}

I think we can generalize the issue and say that the developer shouldn't be able to pass any combination of options to the field that will hide validation messages. Allowing that makes it confusing when we accidentally pass a bad configuration and can't figure out why the validation message isn't showing up. Those are the kinds of things, I think, that make developers shy away from certain libraries.

To Reproduce
🤔 I guess try the above?

  1. Create a boolean field
  2. Don't give it a ui:option of showFieldLabel: true
  3. Give it a custom validation
  4. Go through the form and trigger the validation

Expected behavior
As a developer, I should be able to pass any valid configuration to any field and still expect validation messages to show up when appropriate.

@jcmeloni-usds jcmeloni-usds changed the title Field label required for validation message to be displayed BUG? Field label required for validation message to be displayed Oct 23, 2018
@jcmeloni-usds jcmeloni-usds added the [practice] engineering Engineering related work label Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[practice] engineering Engineering related work
Projects
None yet
Development

No branches or pull requests

2 participants