SugarCRM: Create a custom javascript validation before saving in Edit view

This note will teach you how to call a custom javascript function upon clicking the Save button in Edit view.

1. Create a custom view.edit.php in custom/modules/<module>/view/ and create the javascript function under the preDisplay function. See sample code bellow:

public function preDisplay() {

// Javascript function to call

function customJavascriptValidation() {
// Insert code here

return check_form(“Edit View”); // This will call the default function that sugar use

2. Go tot editviewdefs.php in custom/modules/metadata/ and put the codes below before the widths array:

'form' => 
      array (
        'buttons' => 
        array (
          0 => array (
            'customCode' => '<input type="submit" name="save" id="save" onClick="this.form.return_action.value=\'DetailView\'; this.form.action.value=\'Save\';  return custom_function(\'EditView\');" value="Save">',

* if file doesnt exist then copy the ediviewdefs.php from modules/<module>/metadata/

3. Run Quick Repair and Rebuild.

Tags: ,

5 responses to “SugarCRM: Create a custom javascript validation before saving in Edit view”

  1. António Santos says :

    On Sugar 5.5.4 I had:

    And now, with Sugar 6.5.12, I need to do this?!
    I think this is not so simple than before…😦

  2. johndopeit says :

    I dont know about lower versions of 6 but in 6.5, yes you should.

  3. aviram says :

    Doesn’t work at all , what do i do with the CANCEL button that doesn’t show now. where is it in the sample code above? how do you insert a javascript function code inside a php function and make it work? (customJavascriptValidation)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: