Doyel Mishra
Doyel Mishra

Reputation: 330

Popup message on the user interface

[![enter image description here][1]][1] In this method how can I check if the formkey attribute actually has a value and if it does not then change the status from "saving" to "failing" and a popup message to the user that the particular user task has no form key?

function saveWorkflow () {
      $('#dbs-debug').html('Saving...');
// **************************************************************

      process.id = 'process_' + _flowId;
      process.name = _flowName;
      $('#dbs-form-content > .dbs-form-task').each(function () {
        var userTask = {};
        userTask.name = $(this).attr('data-name');
        userTask.id = $(this).attr('data-id');
        userTask.condition = $(this).attr('data-condition');

        if ($(this).attr('data-type') === "user-task") {
// **************************************************************
          userTask.formKey = $(this).attr('data-formkey');
// **************************************************************
          userTask.cUsers = $(this).attr('data-cusers');
          userTask.cGroups = $(this).attr('data-cgroups');
          userTask.rejstep = $(this).attr('data-rejstep');
          userTask.due = $(this).attr('data-due');
          userTask.reassignment = $(this).attr('data-reassignment');
        } else if ($(this).attr('data-type') === "email-task") {
          userTask.email = $(this).attr('data-email');
        }
        userTask.type = $(this).attr('data-type');
        process.userTasks.push(userTask);
      });


    }


 


  [1]: https://i.sstatic.net/aml39.png

Upvotes: 2

Views: 84

Answers (1)

mplungjan
mplungjan

Reputation: 177950

I would make the formKey required and use the form submit event to save.

Then the code would not even be executed.

Otherwise

function saveWorkflow() {
  $('#dbs-debug').html('Saving...');
  let formKeyError = false;
  // **************************************************************
  process.id = 'process_' + _flowId;
  process.name = _flowName;
  process.userTasks = $('#dbs-form-content > .dbs-form-task').map(function() {
    const userTask = {
      name: $(this).attr('data-name'),
      type: $(this).attr('data-type')
      id: $(this).attr('data-id'),
      condition: $(this).attr('data-condition')
    };

    if ($(this).attr('data-type') === "user-task") {
      // **************************************************************
      const formKey = $(this).attr('data-formkey');
      if (formKey) userTask.formKey = formKey;
      else formKeyError = true;

      // **************************************************************
      userTask.cUsers = $(this).attr('data-cusers');
      userTask.cGroups = $(this).attr('data-cgroups');
      userTask.rejstep = $(this).attr('data-rejstep');
      userTask.due = $(this).attr('data-due');
      userTask.reassignment = $(this).attr('data-reassignment');
    } else if ($(this).attr('data-type') === "email-task") {
      userTask.email = $(this).attr('data-email');
    }
    return userTask
  }).get()
  if (formKeyError) {
     $('#dbs-debug').html('form key missing, saving aborted');
  } else {
    // save here
  }
}

Upvotes: 2

Related Questions