I'm building jquery validation and I need to support it with displaying Dialog.
There are multiple selection/inputs to check against, so as it is now I get multiple dialogs displayed all at once, and would like to display only one dialog with the list of fields that has not been validated (error).
HTML:
<form method='post'>
input 1: <input type="text" id="input1" name="input1" class="in1"><br>
input 2: <input type="text" id="input2" name="input2" class="in2"><br>
input 3: <input type="text" id="input3" name="input3" class="in3"><br>
<input type="submit" value="Submit" id="submit" name="submit">
</form>
<div id="dialog-input1" title="Error" class="val-noshow">Empty Input 1</div>
<div id="dialog-input2" title="Error" class="val-noshow">Empty Input 2</div>
<div id="dialog-input3" title="Error" class="val-noshow">Empty Input 3</div>
jQuery:
$(document).ready(function () {
$("#submit").click(function () {
var input1 = $('#input1').val();
var input2 = $('#input2').val();
var input3 = $('#input3').val();
var valid = true;
if (input1 == "")
{
$('.in1').removeClass('valid').addClass('error');
valid = false;
$(function () {
$("#dialog-input1").dialog({
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
});
}
else {
$('.in1').removeClass('error').addClass('valid');
}
if (input2 == "")
{
$('.in2').removeClass('valid').addClass('error');
$(function () {
$("#dialog-input2").dialog({
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
});
valid = false;
}
else {
$('.in2').removeClass('error').addClass('valid');
}
if (input3 == "")
{
$('.in3').removeClass('valid').addClass('error');
$(function () {
$("#dialog-input3").dialog({
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
});
valid = false;
}
else {
$('.in3').removeClass('error').addClass('valid');
}
return valid;
});
});
CSS:
.val-noshow { display: none; }
.error { border: 1px #F00 solid; color: #F00;}
.valid { border: 1px #979 solid; }
Working sample jsfiddle: https://jsfiddle.net/nitadesign/sd8Lk9dv/
How I can achive that?