Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add presence validation for workflow_actions that require comments #835

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
//= require spot/editor/multi_auth_controlled_vocabulary
//= require language-tagged-autocomplete-setup
//= require multi-auth-input
//= require workflow-action-form
//= require workflow-action-form-validation
45 changes: 45 additions & 0 deletions app/assets/javascripts/workflow-action-form-validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// some basic validations for the workflow_controls form
$(document).ready(function () {
$('#workflow_controls form').on('submit', function (ev) {
// close out any previous errors
$('.workflow-action-validation-error').alert('close');

// these workflow_actions require comments
var workflowActionsRequiringComments = [
'advisor_requests_changes',
'library_requests_changes',
];
var actionName = $('#workflow_controls form input[name="workflow_action[name]"]:checked').val();
var requiresComment = workflowActionsRequiringComments.indexOf(actionName) > -1;
var comment = $('#workflow_action_comment').val().trim();
var alertText;

// an action has been provided, let's validate whether or not it needs a comment as well
if (actionName) {
// no comments required OR comments are required and one is present,
// break out of this function to submit the form
if (!requiresComment || (requiresComment && comment)) { return; }

// otherwise we need a comment, so we'll display the alert
else { alertText = 'Please provide a comment about what changes are desired.'; }
}

// no action has been provided, we need one
else {
alertText = 'Please select an action below.';
}

// stop the submission + insert an alert for the user
ev.preventDefault();

var $alert = $('<div class="alert alert-danger workflow-action-validation-error" role="alert"></div>')
.append('<button type="button" class="close" data-dismiss="alert" aria-label="Close">'
+ '<span aria-hidden="true">&times;</span>'
+ '</button>')
.append(alertText);

$(this).find('.panel-body').prepend($alert);

return false;
});
})
22 changes: 0 additions & 22 deletions app/assets/javascripts/workflow-action-form.js

This file was deleted.