Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include link in form label?

I'm looking to include a link in a form label as such:

<%= form.check_box 'eula' %>
<%= form.label 'eula', "I agree to the <a href='#' id='eula-link'>EULA</a>", class: 'label-checkbox' %>

Rails writes the HTML out, as it probably should, but how would I accomplish this? Clicking EULA opens a JS popup. I was thinking of embedding a link_to in there somehow ?

like image 423
Brian Avatar asked Jun 17 '12 22:06

Brian


People also ask

How do you make a link into a label?

To provide a clear label for a link in Microsoft Office applications: Right-click on a piece of text to open the context menu. Select the Hyperlink option, or press CTRL + k. Note: If the text is already a link, select the text, click or open the context menu, then select Edit Hyperlink, or press CTRL + k.

How do you add a link to a label in HTML?

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a href=” ”>.

What is for in label tag?

The tag defines a label for an input element. The label element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the label element, it toggles the control.

What is the use of label tag in HTML?

HTML <label> tag When writing in HTML, the <label> tag is used to create labels for items in a user interface. Used within <input> tags on a form, the <label> tag is additionally useful because it extends the clickable area of control elements, like buttons.


2 Answers

Using html_safe with parens will render the html, like so:

<%= f.input :eula, :as => :boolean, label: ("I agree to the #{link_to 'Terms of Service', terms_path}.").html_safe %>
like image 126
Robert Strohmeyer Avatar answered Sep 24 '22 07:09

Robert Strohmeyer


Assuming you're using vanilla rails form helpers, you can do this:

f.label :eula do
    'I agree to the #{link_to("EULA", "#")}'
end

Source: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-label

like image 44
Pierre Avatar answered Sep 24 '22 07:09

Pierre