# Bug DREAM-294 - Provide default id for Primer text field clear button

Project: Stream Design System
Status: closed
URL: https://community.openproject.org/work_packages/DREAM-294

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | Frontend components and Primer design system |
| Target versions | 16.2.0 |
| Observed in versions |  |
| Sprint |  |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers | Henriette Darge |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Context

Credits to <mention class="mention" data-id="75686" data-type="user" data-text="@Attila Dombi">@Attila Dombi</mention> for discovering this:

Turbo will fail to morph a response if there are elements like `<div id=""></div>` on the page and in the response. It is an issue with Idiomorph's id map logic. Idiomorph [will collect the empty ids in an id map](https://github.com/bigskysoftware/idiomorph/blob/a6ada993e8c8d7cb30f417983d3b003982d2e9d0/src/idiomorph.js#L1046), and that is being used to match elements faster on the page. However, when the response comes with an empty id, Idiomorph will [try to find it on the page](https://github.com/bigskysoftware/idiomorph/blob/a6ada993e8c8d7cb30f417983d3b003982d2e9d0/src/idiomorph.js#L542), which will raise a javascript error: `Uncaught DOMException: ctx.target.querySelector: '#' is not a valid selector`.

This is a bug in Idiomorph and Attila will raise a ticket there, but as a sidenote, primer could output the [text field's clear button](https://github.com/opf/primer_view_components/blob/82ee3b1411f704fcf7c2da56ccbf44f499a400c0/app/lib/primer/forms/text_field.html.erb#L16) tag with an empty `id=""`, if a `clear_button_id` argument is not explicitly provided.

As a bottom line, when a text field has a close button rendered, it must always have an id, otherwise it turbo will fail to morph the response.

### Steps to reproduce

Create a TextField with `show_clear_button` set to true, but without a `clear_button_id`

e.g.

``` text
render(Primer::Alpha::TextField.new(
  name: :some_name,
  id: some_id,
  label: "My text field",
  show_clear_button: true,
))
```

<br>

### What is the buggy behavior?

  - The button has an empty ID field

**Hint for QA**

This can be tested in the Datepicker by inspecting the closing "x" in either the start or the due date field. The `button` in the DOM need a value for `id`. This is how it currently looks (wrong):

<img class="image_resized op-uc-image op-uc-image_inline" style="width:508px;" src="/api/v3/attachments/566562/content">

### What is the expected behavior?

  - If no ID is provided, there should be a generated default ID

### 

### Environment information

**Browser**

- [x] Chrome
- [x] Firefox
- [x] Safari
- [ ] Mobile Safari
- [ ] Other (please specify)

**Operating System**

- [x] Windows
- [x] Mac OS X
- [ ] Mobile iOS
- [ ] Mobile Android
- [ ] Linux (please specify distro)
- [ ] Chrome OS
- [ ] Other (please specify)

<br>
