Difference between revisions of "Savefunc"

From SmartWiki
Jump to: navigation, search
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
You can use '''savefunc''' to create a custom [[Browser Script]] that runs whenever a record is saved or submitted.
+
{{JavaScript Syntax}}
 +
You can use '''savefunc''' to create a custom [[Browser Script]] that runs whenever a user clicks '''Save''', '''Save Draft''' or '''Submit'''.
  
 
'''Instructions:'''
 
'''Instructions:'''
Line 10: Line 11:
 
'''Example 1:'''
 
'''Example 1:'''
  
  function savefunc(frm)
+
  function savefunc(frm){
     {
+
     ''do this''
    ''do this''
+
    ''RunAnotherFunction()''
    ''RunAnotherFunction()''
+
    ''do that''
    ''do that''
+
    return true
    return true
+
}
    }
 
  
  
Line 25: Line 25:
 
* The following sample [[JavaScript]] function will prompt the [[User|user]] to confirm if they really want to save the record.
 
* The following sample [[JavaScript]] function will prompt the [[User|user]] to confirm if they really want to save the record.
 
<pre>
 
<pre>
function savefunc(frm)
+
function savefunc(frm){
{
+
  var answer = confirm ("Do you really want to save this?")
var answer = confirm ("Do you really want to save this?")
+
  if (answer){
if (answer)
+
      alert ("Consider it done")
  {
+
      return true
  alert ("Consider it done")
+
   }else{
  return true
+
      alert ("Keep filling it in then")
   }
+
      return false
else
 
  {
 
  alert ("Keep filling it in then")
 
  return false
 
 
   }
 
   }
 
}
 
}
Line 42: Line 38:
 
* ''The "return false" isn't strictly necessary. If the function does not return true then false is assumed.''
 
* ''The "return false" isn't strictly necessary. If the function does not return true then false is assumed.''
  
[[Category:JavaScript]]
+
===See Also===
 +
* [[sbfunc]]
 +
* [[onloadfunc]]
 +
 
 +
[[Category:JavaScript]][[Category:Validation]]

Latest revision as of 15:56, 13 May 2014

This feature uses JavaScript syntax
Text code javascript.gif

You can use savefunc to create a custom Browser Script that runs whenever a user clicks Save, Save Draft or Submit.

Instructions:

  • Create a Custom Field on the page of type: Custom Field Type: Special – Browser Script
  • Include a function in the Browser Script called savefunc that includes the JavaScript you wish to execute when the record is either saved or submitted.
  • The function must return either a value of true if the record should be saved/submitted; or false if the record should not be saved/submitted.
  • Standard and Custom Field validation is performed after this script is run, provided that the function has returned true. If the function returns false no further validation is performed and the record is not saved/submitted.


Example 1:

function savefunc(frm){
   do this
   RunAnotherFunction()
   do that
   return true
}



Example 2:

  • The following sample JavaScript function will prompt the user to confirm if they really want to save the record.
function savefunc(frm){
   var answer = confirm ("Do you really want to save this?")
   if (answer){
      alert ("Consider it done")
      return true
   }else{
      alert ("Keep filling it in then")
      return false
   }
}
  • The "return false" isn't strictly necessary. If the function does not return true then false is assumed.

See Also