JSFiddle - React, Tailwind, and code Playground
by Serg Sagan
JavaScript
//полный кусок кода (рабочий)
$(document)
.on('click', '.btn-save', function (e) {
e.preventDefault();
<% if !@activity.draft? %>
var reasons = [];
if ($('#activity_start_date').length && !$('#activity_start_date').val()) {
reasons.push("specify assign date");
}
if ($('#activity_due_date').length && !$('#activity_due_date').val()) {
reasons.push("specify due date");
}
if ($('.activity-content .items .activity-content-item').length == 0) {
reasons.push("add quiz questions");
}
$('.activity-content [required=required]').each(function (i, requiredField) {
$(requiredField).valid();
});
if ($('[aria-invalid=true]').length > 0) {
reasons.push("fill all required fields");
}
var choices = $('.activity-content-item .choices');
for (var c = 0; c < choices.length; c++) {
if ($(choices[c]).find('input:checkbox:checked').length == 0) {
reasons.push('select at least one correct answer for each multiple choice question');
}
}
if (reasons.length) {
sweetAlert({
showCancelButton: false,
confirmButtonText: 'OK',
title: 'Cannot save quiz',
text: 'In order to save quiz, you must: <br> – ' + _.join(reasons, '<br> – '),
type: "warning"
});
} else {
autoSaveActivity(false, function() {
show_top_alert_message('success', 'Quiz successfully saved')
}, true);
return false;
}
<% else %>
autoSaveActivity(false, function() {
show_top_alert_message('success', 'Quiz successfully saved')
}, true);
return false;
<% end %>
})
.on('click', '.btn-preview', function (e) {
e.preventDefault();
<% if !@activity.draft? %>
var reasons = [];
if ($('#activity_start_date').length && !$('#activity_start_date').val()) {
reasons.push("specify assign date");
}
if ($('#activity_due_date').length && !$('#activity_due_date').val()) {
...