Update submission text when it matches any default type of text
This commit is contained in:
parent
0e033e7074
commit
386577cd21
1 changed files with 22 additions and 7 deletions
|
|
@ -149,13 +149,23 @@ function word_count(text, divId, maxcount) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function fill_if_empty(text_area, filler) {
|
function replace_defaut_submission_text(input_selector, new_text, valid_defaults) {
|
||||||
let area = $('#' + text_area);
|
let $area = $(input_selector);
|
||||||
|
let current_text = $area.val();
|
||||||
|
|
||||||
if (!area.val()) {
|
if (!current_text) {
|
||||||
area.val(filler);
|
$area.val(new_text);
|
||||||
area.trigger('change');
|
$area.trigger('change');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valid_defaults.some(default_text => {
|
||||||
|
if (current_text == default_text) {
|
||||||
|
$area.val(new_text);
|
||||||
|
$area.trigger('change');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
|
@ -166,8 +176,13 @@ $( document ).ready(function() {
|
||||||
var max = $selected.data("max-words");
|
var max = $selected.data("max-words");
|
||||||
var min = $selected.data("min-words");
|
var min = $selected.data("min-words");
|
||||||
|
|
||||||
// Set the filler text for the submission text
|
// We replace the default text only if the current field is empty,
|
||||||
fill_if_empty('event_submission_text', $selected.data("instructions"));
|
// or is set to the default text of another event type.
|
||||||
|
replace_defaut_submission_text(
|
||||||
|
'#event_submission_text',
|
||||||
|
$selected.data("instructions"),
|
||||||
|
$("#event_event_type_id option").toArray().map(e => $(e).data('instructions'))
|
||||||
|
);
|
||||||
|
|
||||||
$("#abstract-maximum-word-count").text(max);
|
$("#abstract-maximum-word-count").text(max);
|
||||||
$("#submission-maximum-word-count").text(max);
|
$("#submission-maximum-word-count").text(max);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue