0

I am using the summernote WYSIWYG editor along with SimpleForm.

So this form field:

<%= f.input :description, as: :summernote, placeholder: "Enter the description of the Job (e.g. 'Product Manager', 'Senior Ruby on Rails Developer')" %>

Generates the following HTML:

<textarea class="summernote optional" placeholder="Enter the description of the Job (e.g. 'Product Manager', 'Senior Ruby on Rails Developer')" data-provider="summernote" name="job[description]" id="job_description" style="display: none;"></textarea>

My SummerNote JS is executed as follows:

ready = ->
  $('[data-provider="summernote"]').each ->
    $(this).summernote(height: 300, toolbar: [['style', ['bold', 'italic', 'underline', 'clear', 'fontname', 'fontsize', 'color']],
    ['font', ['strikethrough', 'superscript', 'subscript']], ['para', ['ul', 'ol', 'paragraph']],
    ['height', ['height']], ['insert', ['link', 'table', 'hr']]], placeholder: "Some placeholder copy")

$(document).ready(ready)
$(document).on('turbolinks:load', ready)

However, instead of the Some placeholder copy, I would like to pull the value that is specified in the form (i.e. the placeholder in the <textarea> field).

How do I do that?

1 Answer 1

1
$(this).attr "placeholder" # => the attribute value

It's basic jQuery. this is the textarea, and .attr is the jQuery method for reading/writing attribute values.

Sign up to request clarification or add additional context in comments.

3 Comments

Perfect. Just what I was looking for. Thanks!
$(@), to match coffeescript style anstead of $(this)
@Exinferis Both are valid. Personally, I prefer to use this when I'm just referring to the object itself, and @something when referring to a property/method. Personal preference, sure, but I just think @ looks odd by itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.