From 1f9da86e39fd4f5b1b89dcba1d0e779dbf5d47be Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Thu, 4 Mar 2021 23:43:27 -0800 Subject: [PATCH] Fill submission text if the field is currently empty --- app/assets/javascripts/osem.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index 0839f13b..59174f01 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -147,6 +147,15 @@ function word_count(text, divId, maxcount) { }); }; +function fill_if_empty(text_area, filler) { + let area = $('#' + text_area); + + if (!area.val()) { + area.val(filler); + area.trigger('change'); + } +} + /* Wait for the DOM to be ready before attaching events to the elements */ $( document ).ready(function() { /* Set the minimum and maximum proposal abstract and submission text word length */ @@ -155,15 +164,15 @@ $( document ).ready(function() { var max = $selected.data("max-words"); var min = $selected.data("min-words"); + // Set the placeholder text for the abstract + fill_if_empty('event_submission_text', $selected.data("help")); + $("#abstract-maximum-word-count").text(max); $("#submission-maximum-word-count").text(max); $("#abstract-minimum-word-count").text(min); $("#submission-minimum-word-count").text(min); 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');