Skip to content

Handle both negative and positive values when creating ids for checkboxes/radios #591

@jf-x-dev

Description

@jf-x-dev

We get HTML ids for elements from this method:

def build_id(id_type, delimiter = '-', replace = '_', attribute_name: nil, include_value: true)

So when creating checkboxes with values 1, 2, 3, we get elements with ids my-checkbox-1-field, my-checkbox-2-field, my-checkbox-3-field etc.

If we instead want to create checkboxes with values -1, -2, -3, we still get elements with ids my-checkbox-1-field, my-checkbox-2-field, my-checkbox-3-field due to the parameterize call in the above method.

There are some use cases where we want checkboxes with values that are both positive and negative. For example, for school years, you may have checkboxes for Nursery, Reception, Year 1, Year 2, which correspond to values -1, 0, 1, 2 internally.

In this case, you end up with two elements with the same HTML id (my-checkbox-1-field) which is very bad for both accessibility and automated E2E testing.

I'd be interested in hearing:

  1. if this is something that should be handled
  2. if so, how we should implement this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions