js/insertVote.js
// Verify that the amount of choices match the number of total votes
Verify that the amount of choices match the number of total votes
Verify that the amount of choices match the number of total votes
function verifyTotals() {
    var numberOfVotes   = Number(numberOfVotesEl.val());
    formValid           = batchNameUnique;
    for(var i=0; i<sgqas.length; i++) {
      var totalInput = FORM.find('input[name="total-'+ sgqas[i] +'"]:not(.admin)');
      if (totalInput.length > 0) {
        var total      = Number(totalInput.val());
        var formGroup  = totalInput.parents(".form-group");
        if (numberOfVotes != 0 && total != 0 && total == numberOfVotes) {
          formGroup.removeClass('has-error').addClass('has-success');
        }
        else {
          formGroup.addClass('has-error').removeClass('has-success');
          formValid = false;
        }
      }
    }
  }
function verifyTotals ( ) { var numberOfVotes = Number ( numberOfVotesEl . val ( ) ) ; formValid = batchNameUnique ; for ( var i = 0 ; i < sgqas . length ; i ++ ) { var totalInput = FORM . find ( 'input[name="total-' + sgqas [ i ] + '"]:not(.admin)' ) ; if ( totalInput . length > 0 ) { var total = Number ( totalInput . val ( ) ) ; var formGroup = totalInput . parents ( ".form-group" ) ; if ( numberOfVotes != 0 && total != 0 && total == numberOfVotes ) { formGroup . removeClass ( 'has-error' ) . addClass ( 'has-success' ) ; } else { formGroup . addClass ( 'has-error' ) . removeClass ( 'has-success' ) ; formValid = false ; } } } }
Verify that the amount of choices match the number of total votes
Verify that the amount of choices match the number of total votes
// We assume everything will be valid if name is unique // For each question... // Could have more than one answer per question