# Question on data-controller-target

**URL:** https://discuss.hotwired.dev/t/question-on-data-controller-target/3983
**Category:** General
**Created:** [March 30, 2022, 6:24pm UTC](https://discuss.hotwired.dev/t/question-on-data-controller-target/3983 "2022-03-30T18:24:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spacerobotTR](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/spacerobottr/32/223_2.png) [@spacerobotTR](https://discuss.hotwired.dev/u/spacerobotTR)
#### Post date: [March 30, 2022, 6:24pm UTC](https://discuss.hotwired.dev/t/question-on-data-controller-target/3983/1 "2022-03-30T18:24:44Z")

</div>

What would be the rails text\_field helper equivalent of this?

`<input type="text" data-total-target="qty" class= "form-control" name="qty" id="qty" data-action="change->total#settotal">`

I wasn’t sure how to specify the data-total-target with the text\_field helper.

Thanks.

---

<div class="post-metadata">

### Author: ![walterdavis](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/walterdavis/32/737_2.png) [@walterdavis](https://discuss.hotwired.dev/u/walterdavis)
#### Post date: [March 30, 2022, 7:18pm UTC](https://discuss.hotwired.dev/t/question-on-data-controller-target/3983/2 "2022-03-30T19:18:38Z")

</div>

Is the field really named just `qty`? That would mean to me that it was made with the `text_field_tag` helper rather than the `text_field` helper, since the latter always binds the form field to an instance of your model, and the fields are named something like `your_model_name[qty]` rather than just `qty`.

```nohighlight
f.text_field :qty, class: 'form_control', 
                         data: {
                           action: 'change->total#settotal',
                           total: { target: 'qty' }
                         }

```

…ought to do it. If you find that the data-total-target doesn’t come out kebab-case like you want it with my nested syntax, you can also do `data: { action: '...', 'total-target': 'qty' }` and that will guaranteed work. The data: key always concatenates to it’s direct children with a - rather than a \_, but I don’t know off-hand if it always does that with all of its descendants.

It is also entirely okay (if a little more duplicative and long-hand) to just make up a symbol for each of the data tags you want to add, like `'data-foo-bar': 'baz', 'data-blarg-boo: 'blooey'`. That also works and you end up with the same attributes.

Walter

---

<div class="post-metadata">

### Author: ![spacerobotTR](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/spacerobottr/32/223_2.png) [@spacerobotTR](https://discuss.hotwired.dev/u/spacerobotTR)
#### Post date: [March 30, 2022, 7:46pm UTC](https://discuss.hotwired.dev/t/question-on-data-controller-target/3983/3 "2022-03-30T19:46:04Z")

</div>

Thanks!

This worked!

`<%= form.text_field :qty, class: 'form-control', data: {action: 'change->total#settotal', 'total-target': 'qty'} %>`
