Add JavaScript to make placeholder text update along with word count

This commit is contained in:
CactusPuppy 2021-02-18 23:27:20 -08:00
parent 16d9dfef4c
commit d46e1e7397
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
3 changed files with 25 additions and 10 deletions

View file

@ -149,15 +149,21 @@ function word_count(text, divId, maxcount) {
/* Wait for the DOM to be ready before attaching events to the elements */ /* Wait for the DOM to be ready before attaching events to the elements */
$( document ).ready(function() { $( document ).ready(function() {
/* Set the minimum and maximum proposal abstract word length */ /* Set the minimum and maximum proposal abstract and submission text word length */
$("#event_event_type_id").change(function () { $("#event_event_type_id").change(function () {
var $selected = $("#event_event_type_id option:selected") var $selected = $("#event_event_type_id option:selected")
var max = $selected.data("max-words"); var max = $selected.data("max-words");
var min = $selected.data("min-words"); var min = $selected.data("min-words");
$("#abstract-maximum-word-count").text(max); $("#abstract-maximum-word-count").text(max);
$("#submission-maximum-word-count").text(max);
$("#abstract-minimum-word-count").text(min); $("#abstract-minimum-word-count").text(min);
$("#submission-minimum-word-count").text(min);
word_count($('#event_abstract').get(0), 'abstract-count', max); word_count($('#event_abstract').get(0), 'abstract-count', max);
word_count($('#event_submission_text').get(0), 'submission-count', max);
// Set the placeholder text for the abstract
$('#event_submission_text').attr("placeholder", $selected.data("help"));
}) })
.trigger('change'); .trigger('change');
@ -167,6 +173,13 @@ $( document ).ready(function() {
var max = $selected.data("max-words"); var max = $selected.data("max-words");
word_count(this, 'abstract-count', max); word_count(this, 'abstract-count', max);
} ); } );
/* Count the submission text length */
$("#event_submission_text").bind('change keyup paste input', function() {
var $selected = $("event_event_type_id option:selected")
var max = $selected.data("max-words");
word_count(this, 'submission-count', max);
});
}); });
/* Commodity function for modal windows */ /* Commodity function for modal windows */

View file

@ -13,7 +13,7 @@
= f.input :event_type_id, as: :select, = f.input :event_type_id, as: :select,
collection: @conference.program.event_types.map {|type| ["#{type.title} - #{show_time(type.length)}", type.id, collection: @conference.program.event_types.map {|type| ["#{type.title} - #{show_time(type.length)}", type.id,
data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length }]}, data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length, help: type.description }]},
include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' } include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' }
- if @program.languages.present? - if @program.languages.present?
@ -46,17 +46,19 @@
250 250
words. words.
= f.input :submission_text, input_html: { rows: 5, data: { provide: 'markdown' } }, %br
hint: markdown_hint('[Tips to improve your presentations.](http://blog.hubspot.com/blog/tabid/6307/bid/5975/10-Rules-to-Instantly-Improve-Your-Presentations.aspx)')
= f.input :submission_text, input_html: { rows: 5, data: { provide: 'markdown' }, placeholder: '' },
hint: markdown_hint('Only conference organizers will read this.')
%p %p
You have used You have used
%span#abstract-count #{@event.submission_word_count} %span#submission-count #{@event.submission_word_count}
words. Submission descriptions must be between words. Submission descriptions must be between
%span#abstract-minimum-word-count %span#submission-minimum-word-count
0 0
and and
%span#abstract-maximum-word-count %span#submission-maximum-word-count
250 250
words. words.

View file

@ -66,12 +66,12 @@
%p %p
You have used You have used
%span#abstract-count #{@event.submission_word_count} %span#submission-count #{@event.submission_word_count}
words. Submission descriptions must be between words. Submission descriptions must be between
%span#abstract-minimum-word-count %span#submission-minimum-word-count
0 0
and and
%span#abstract-maximum-word-count %span#submission-maximum-word-count
250 250
words. words.