Reputation: 393
I would like to know if there is a way to add buttons in form_for so they will edit text_area.
<%= form_for(@post) do |f| %>
<div class="field
<%= f.label :content %><br>
<%= f.text_area :content, :size => "70x20" %>
</div>
this is part of my form_for and I would like to add some buttons with HTML tags which would insert text inside text_area like
<b></b> <i></i>
Is it possible ? Thank you.
Upvotes: 0
Views: 647
Reputation: 5192
This is a job for javascript. There are a lot of different resources to check out online.
There are also a lot of prebuilt ones. You can check out (in no particular order):
In very basic javascript, you could do something like:
<%= link_to("Bold", '#', onclick: "myFunction(); return false") %>
<script>
function myFunction() {
var textArea = document.getElementById('post_content');
textArea.value += "<b></b>";
}
</script>
Upvotes: 1