Quantcast
Channel: Discussion Forum > Connect Data Services
Viewing all articles
Browse latest Browse all 2504

Javascript API -Problem with onbeforesave()

$
0
0

Topic by Angeliki Kanavaru

Hello all,

I'm trying to validate  the input for a custom field (the birthdate text field) using the Javascript API and the onbeforesave() function.

The onbeforesave() function is called when I open an existing contact and modify data and then trying to save them only the first time.

For example if I change the birthdate and press Save the onbeforesave() function is called, validates my input and prompts a message.

Lets say that the abovementioned input was wrong and I change its value and press Save again,  the onbeforesave() function isn't called, thus the validation doesn't occur.

What I'm trying to say is that the onbeforesave() function is called only ony the first time I press Save  for a record (either new or existed) and not every time I press Save.

Here is the code I'm using :

<script type="text/javascript">
 
 
function onbeforesave()
{
   var date = window.external.Contact.GetCustomFieldByName("c$birthdate");
 
if(date!=null)
{
var reg=/^(0[1-9]|1[0-2])[/](0[1-9]|[1-2][0-9]|3[0-1])[/](19|20)\d\d$/;
var check = false;
 
if( reg.test(date))
{
document.write("Valid value");
var success = true;
// execute the response
window.external.beforesavecomplete(success, "Save OK!");}
 
else
{
 
document.write("Invalid value");
var success = false;
window.external.beforesavecomplete(success, "Invalid value for Birth Date");}
 
 
}
else
{document.write("Not set yet!");}  
}
</script>
Any ideas?

Viewing all articles
Browse latest Browse all 2504

Trending Articles