Hotwire Discussion

Target attribute on turbo-frame tags

I’m struggling a bit with the target attribute. it works pretty good with ‘_top’, but according to the docs, when I want to affect a turbo-frame context ‘b’ from within a turbo-frame context ‘a’ I should use the target=‘b’ option.

By default, navigation within a frame will target just that frame. This is true for both following links and submitting forms. But navigation can drive the entire page instead of the enclosing frame by setting the target to _top . Or it can drive another named frame by setting the target to the ID of that frame.

It turns out that it’s not working at all, I’m using something like that:

<turbo-frame id='a' target='b'>
 <!-- some action -->

<turbo-frame id='b'>
 <!-- result -->

Also, my response do have the turbo-frame context b.

Have you guys faced this behavior as well ?.

I tried it to and you’re right. The same for me, the setting the target to another frame does not seem to work.

the turbo-stream though, has a target attribute, I wonder if it’s just a documentation issue

The functionality described in the docs makes perfect sense though

I interpreted the documentation in the same way as written above. I am also unable to get the desired behavior solely using <turbo-frame> with the target attribute.

The only way I’ve been able to get the desired behavior is to create and respond with turbo_stream.erb template:

<turbo-stream action='replace' target='b'>
    <turbo-frame id='b'>
      <!-- your content here -->
1 Like