Skip to content

Commit

Permalink
Fixed issue #17685: When adding a new participant, user is able to Sa…
Browse files Browse the repository at this point in the history
…ve without adding any information and a blank record is save (#2194)

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik and encuestabizdevgit committed Feb 17, 2022
1 parent 2ffb2fd commit 190dad1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
21 changes: 21 additions & 0 deletions application/views/admin/token/tokenform.php
Expand Up @@ -480,3 +480,24 @@ class='form-control<?= $attr_description['mandatory'] == 'Y' ? ' mandatory-attri
LS.renderBootstrapSwitch();
", LSYii_ClientScript::POS_POSTSCRIPT);
?>

<?php if ($token_subaction == "addnew"): ?>
<!-- Empty Token Confirmation Modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="emptyTokenConfirmationModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><?= gT('Create empty participant') ?></h4>
</div>
<div class="modal-body">
<?= gT("You are about to create a participant without the basic details. Are you sure you want to proceed?") ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-cancel" data-dismiss="modal"><?php eT("Cancel");?></button>
<button type="button" class="btn btn-primary" id="save-empty-token"><?php eT("Save");?></button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php endif; ?>
29 changes: 28 additions & 1 deletion assets/scripts/admin/tokens.js
Expand Up @@ -208,6 +208,22 @@ function validateAdditionalAttributes() {
return valid;
}

/**
* Validates some form fields checking that at least one is not empty when creating a participant.
* @returns {boolean} false if all of the checked fields are empty and the subaction is inserttoken.
*/
function validateNotEmptyTokenForm() {
if ($('#edittoken').find('[name="subaction"]').val() != 'inserttoken') {
return true;
}
var isFormEmpty = $('#email').val() == '' && $('#firstname').val() == '' && $('#lastname').val() == '';
if (isFormEmpty) {
$('#emptyTokenConfirmationModal').modal('show');
return false;
}
return true;
}

/**
* Scroll the pager and the footer when scrolling horizontally
*/
Expand Down Expand Up @@ -282,7 +298,8 @@ $(document).on('ready pjax:scriptcomplete', function(){

$(document).off('click.edittoken', '.edit-token').on('click.edittoken', '.edit-token', startEditToken);

$(document).off('submit.edittoken', '#edittoken').on('submit.edittoken', '#edittoken', function(event){
$(document).off('submit.edittoken', '#edittoken').on('submit.edittoken', '#edittoken', function(event, params){
var eventParams = params || {};
if($('#editTokenModal').length > 0 ){
event.preventDefault();
submitEditToken();
Expand All @@ -292,6 +309,9 @@ $(document).on('ready pjax:scriptcomplete', function(){
event.preventDefault();
return false;
}
if (!eventParams.confirm_empty_save && !validateNotEmptyTokenForm()) {
return false;
}
});

/**
Expand All @@ -303,6 +323,13 @@ $(document).on('ready pjax:scriptcomplete', function(){
}
});

/**
* Confirm save empty token
*/
$("#save-empty-token").off('click.token-save').on('click.token-save', function() {
$('#edittoken').trigger('submit', {confirm_empty_save: true});
});


$('#startbounceprocessing').click(function(){

Expand Down

0 comments on commit 190dad1

Please sign in to comment.