Created
January 26, 2018 21:55
-
-
Save ryenski/3973b2816fa9a4e54f818219fbc0988c to your computer and use it in GitHub Desktop.
Clickable table rows with Stimulus.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tr data-action="click->table#click" data-controller="table"> | |
<td> 2018-01-11 </td> | |
<td> | |
<a data-target="table.url" href="/invoices/1">$7,000.00</a> | |
</td> | |
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "stimulus" | |
export default class extends Controller{ | |
click(e){ | |
Turbolinks.visit(this.url) | |
} | |
get url() { | |
return this.targets.find('url').href | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment