bug 5817: validate vm dropdown (empty or having value) before creating port forwarding rule.

This commit is contained in:
Jessica Wang 2010-11-16 10:30:24 -08:00
parent ed31497188
commit 4a3ad7c5e9
3 changed files with 19 additions and 3 deletions

View File

@ -195,6 +195,7 @@
<div class="grid_row_cell" style="width: 39%;">
<select class="select" id="vm">
</select>
<div id="vm_errormsg" class="errormsg" style="display: none;"></div>
</div>
<div class="grid_row_cell" style="width: 15%;">
<div class="row_celltitles">

View File

@ -86,10 +86,11 @@ function afterLoadIpJSP() {
//*** Acquire New IP (end) ***
//Port Fowording tab
var $createPortForwardingRow = $("#tab_content_port_forwarding #create_port_forwarding_row");
var $createPortForwardingRow = $("#tab_content_port_forwarding").find("#create_port_forwarding_row");
$createPortForwardingRow.find("#add_link").bind("click", function(event){
var isValid = true;
var isValid = true;
isValid &= validateDropDownBox("Instance", $createPortForwardingRow.find("#vm"), $createPortForwardingRow.find("#vm_errormsg"));
isValid &= validateNumber("Public Port", $createPortForwardingRow.find("#public_port"), $createPortForwardingRow.find("#public_port_errormsg"), 1, 65535);
isValid &= validateNumber("Private Port", $createPortForwardingRow.find("#private_port"), $createPortForwardingRow.find("#private_port_errormsg"), 1, 65535);
if (!isValid) return;

View File

@ -1544,6 +1544,20 @@ function showError2(isValid, field, errMsgField, errMsg, appendErrMsg) {
}
}
function showErrorInDropdown(isValid, field, errMsgField, errMsg, appendErrMsg) {
if(isValid) {
errMsgField.text("").hide();
field.addClass("select").removeClass("error_select");
}
else {
if(appendErrMsg) //append text
errMsgField.text(errMsgField.text()+errMsg).show();
else //reset text
errMsgField.text(errMsg).show();
field.removeClass("select").addClass("error_select");
}
}
function validateDropDownBox(label, field, errMsgField, appendErrMsg) {
var isValid = true;
var errMsg = "";
@ -1552,7 +1566,7 @@ function validateDropDownBox(label, field, errMsgField, appendErrMsg) {
errMsg = label + " is a required value. ";
isValid = false;
}
showError2(isValid, field, errMsgField, errMsg, appendErrMsg);
showErrorInDropdown(isValid, field, errMsgField, errMsg, appendErrMsg);
return isValid;
}