Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom object to verify textbox value format on Save and Save and close

grv.mishra
Collaborator III

Hello All,

 

                I have a requirement to validate format of input text field on save or save and close. I want to skip this validation if this filed is black or not in DOM. I wrote below code but this code broke Save and Save and Close functionality also I dont see any error on console. Please suggest how to go about it. Also I need to abort save in case format is not matching, In my script if format is not matching popup is shown but on click of ok save happens which I want to avoid.

 

<script>

Sys.Application.add_load(function() {
$('#master_btnSave').removeAttr('onclick').click(function() { CheckIP(); return false; });
$('#master_btnApply').removeAttr('onclick').click(function() { CheckIP(); return false; });
var timer = null;
var inputControl = $("span:contains('Machine(s) / System(s):')").parent().next().find('input').next();
inputControl.keydown(function(){
clearTimeout(timer);
timer = setTimeout(CheckIP, 2000)
});

});

function CheckIP(){

if(!($("span:contains('Machine(s) / System(s):')").parent().next()[1]))
{
return;
}
var Result=-1;

var ArrSp=$("span:contains('Machine(s) / System(s):')").parent().next()[1].getElementsByTagName("p")[0].innerText.trim();
if(ArrSp.trim() !=""){
var aa=ArrSp.split(",");

for (i = 0; i < aa.length; i++) {
var CheckIP = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
var CheckDomainName=/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/;
var Subnet1 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
var Subnet2 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d+$/;
if(aa !="" ){
if(CheckIP.test(aa.trim()) || CheckDomainName.test(aa.trim()) || Subnet1.test(aa.trim()) || Subnet2.test(aa.trim()))
{
}
else
{
Result=i;
}
}
}
if(Result>-1){
WarningAlert(aa[Result]+ " is not fully qualified domain name/IP or Subnet.","Machine(s) / System(s): format warning");
return;
}
}
}
</script>

21 REPLIES 21

Well, this will run then only once. And if your status changes only per save, would work.

But it will not be like DDE real time hooking.

Status change is done via advance workflow update content node not via dde.

Should work then, just try it out.

grv.mishra
Collaborator III

<script>
Sys.Application.add_load(function () {

var overallStatus = $("span:contains('Overall Status:')").parent().next().find('li')[0].innerText.trim();
if(overallStatus == "In Draft")
{
$('#master_btnSave').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnSave');
$('#master_btnSave').hide();
$('#master_customBtnSave').unbind('click').prop("onclick", null).click(function(){ CheckIP('save');return false;});

$('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
$('#master_btnApply').hide();
$('#master_customBtnApply').unbind('click').prop("onclick", null).click(function(){ CheckIP('apply');return false;});
var timer = null;
var inputControl = $("span:contains('Machine(s) / System(s):')").parent().next().find('input').next();
inputControl.keydown(function(){
clearTimeout(timer);
timer = setTimeout(CheckIP, 2000)
});
}

});

function CheckIP(action)
{
if(!($("span:contains('Machine(s) / System(s):')").parent().next()[1]))
{

if (action == 'save')
{
$('#master_btnSave').click();
}
else if (action == 'apply')
{
$('#master_btnApply').click();
}
return;
}
var Result=-1;
var ArrSp=$("span:contains('Machine(s) / System(s):')").parent().next()[1].getElementsByTagName("p")[0].innerText.trim();
if(ArrSp.trim() !="")
{
var aa=ArrSp.split(",");

for (i = 0; i < aa.length; i++)
{
var CheckIP = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
var CheckDomainName=/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/;
var Subnet1 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
var Subnet2 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d+$/;
if(aa !="" )
{
if(CheckIP.test(aa.trim()) || CheckDomainName.test(aa.trim()) || Subnet1.test(aa.trim()) || Subnet2.test(aa.trim()))
{

}
else
{
Result=i;
}
}

}

}

if(Result>-1)
{
WarningAlert(aa[Result]+ " is not fully qualified domain name/IP or Subnet.","Machine(s) / System(s): format warning");
return;
}

if (action == 'save')
{
$('#master_btnSave').click();
}
else if (action == 'apply')
{
$('#master_btnApply').click();
}
}

</script>

This is the working script, thnx Ilya Khen‌ for your inputs.

Anytime

Vishakhanarayan
Contributor

Hi @Ilya_Khen I am from the same company, this was working script way back now it is not working after upgrade. Current version of archer is 6.9 P2 HF1. Can you please help what needs to be changed.

 

Ilya_Khen
Champion III

That depends on what is not working and which version you had upgrade from.

Vishakhanarayan
Contributor

Entire script is not working. There was a popup message when user clicks 'apply' and 'save'. Now the buttons are save and save and close.

It was working in 6.7 I guess. After that we did couple of upgrade. Current version is 6.9 P2 HF1.

It was working when archer used to have buttons 'save' and 'apply' and stopped when the button renamed to 'save' and 'save and close'

Ilya_Khen
Champion III

Should be working still I guess. Especially when buttons are still saving.

If you attach the script here, maybe it would be possible to see some hint.