I've been asked to convert a VB6
application to a WebForms
environment (C# .NET v4.5)
. The existing application presents multiple confirmation messages when the Save button is clicked.
EG. "You have entered X, which is less than Y. Are you sure?"
They want to preserve this functionality but I'm uncomfortable with this approach of spamming the user with (potentially) 10+ questions that they have to click through in order to save. Not to mention that modern browsers allow users to disable multiple popups.
So does anyone have a more 'best practice' approach to this scenario?
In case anyone else comes across this requirement, here is the solution I came up with. It's a bit rough and I need to do further work on cleaning it up, but it might provide a starting point for someone in the future.
http://jsfiddle.net/Sam_Banks/df3cewg7/
It is a simple <UL>
that is built up using JQuery
as a result of validation checks run when a button is clicked.
<div>
<label for="txtCaseOne">First Input</label>
<input id="txtCaseOne" type="text" />
</div>
<div>
<label for="txtCaseTwo">Second Input</label>
<input id="txtCaseTwo" type="text" />
</div>
<div>
<input type="button" id="btnSubmit" value="OK" />
</div>
<div class="confirmationContainer">
<div class="confirmationWindow">
<ul class="warnings"></ul>
</div>
</div>
Each list item consists of a message and a checkbox. The message text is clickable and takes the user to the target control so that they can check/edit a value as required.
The checkbox allows the user to register that they have confirmed the warning.
The user's confirmations are remembered so that they don't have to re-confirm if the dialog is closed & re-opened.
The page will not submit to the server unless all checkboxes have been clicked.
function submitFinalApproval() {
var unconfirmed = $('.confirmationWindow').find('input:checkbox:not(:checked)');
if (unconfirmed.length > 0) {
alert("You cannot submit for Final Approval until all warnings are confirmed.");
return false;
}
alert("Submitting");
$('.confirmationWindow').dialog('close');
}
function cancelFinalApproval() {
$('.confirmationWindow').dialog('close');
}
function saveCheckedWarnings() {
$('.confirmationContainer').removeData();
var checkedWarnings = $('.confirmationWindow input:checked');
checkedWarnings.each(function () {
var warning = $(this).parent().siblings('span').text();
$('.confirmationContainer').data(warning, "true");
});
}
function selectWarning(target) {
$('.confirmationWindow').dialog('close');
target.focus().select();
}
function appendWarning(message, target) {
var label = $('<span>');
label.text(message);
label.on('click', function () {
selectWarning(target);
});
var checkboxLabel = $('<label>');
if ($('.confirmationContainer').data(message)) {
checkboxLabel.append($('<input type="checkbox" checked="checked" />'));
} else {
checkboxLabel.append($('<input type="checkbox" />'));
}
checkboxLabel.append('OK');
$('.warnings')
.append($('<li>')
.append(label)
.append(checkboxLabel));
}
$('#btnSubmit').click(function () {
//if page passes error validation
$('.warnings').empty();
// If warning condition 1 fails
appendWarning("Please note that Condition 1 is odd. Would you like to continue?", $('#txtCaseOne'));
// If warning condition 2 fails
appendWarning("Condition 2 set to Fizz while Buzz. Are you sure?", $('#txtCaseTwo'));
// If warning condition 3 fails
appendWarning("Condition 3. Are you sure?", $('#txtCaseTwo'));
$('.confirmationWindow').dialog('open');
return false;
});
$('.confirmationWindow').dialog({
autoOpen: false,
modal: true,
dialogClass: 'noDialogTitle',
buttons: {
"Submit for Final Approval": submitFinalApproval,
Cancel: cancelFinalApproval
},
close: function () {
saveCheckedWarnings();
}
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments