Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
linenumberstrue
$jQuery.njDialerPlugin.onConnect=
function ()
{ 
    // Create a custom regex validator
    jQuery.validator.addMethod("regex", function(value, element, param) 
    {
        return value.match(new RegExp("." + param + "$"));
    });
    
    // now use it as follows
    // First set a message to display when it fails
    jQuery.validator.messages.regex = 'The field did not match the required pattern';
    
    // Enable validation on the form
    jQuery(jQuery.njDialerPlugin.getForm()).validate();
    
    // Use our custom validator to force the field to only have alpha characters or a space.
    jQuery.njDialerPlugin.getFields("due_date")
        .rules('add', { required : true, regex : "[a-zA-Z ]+});
};



Because the event handler for sending emails is executed asynchronously and typically before any validation code in JavaScript. Modification of the HTML hfer tag generated by the built in tools needs to be modified to handle field validation.

Switch to HTML editor in the screen layout, find <a href> tag and modify the onclick argument to  onclick="return false;"

See sample below:

Modify from:

Code Block
linenumberstrue
<a href="sendEmailTemplate&to=${custom_email}&cc=&from=sender%40test.com&subject=Message+from+Sender&templateId=59" id="my-link" onclick="newUrlPath(this);return false;" showallfields="true">Email to Lead</a>


to:

Code Block
<a href="sendEmailTemplate&to=${custom_email}&cc=&from=sender%40test.com&subject=Message+from+Sender&templateId=59" id="my-link" onclick="return false;" showallfields="true">Email to Lead</a>


Add JavaScript for Field Validation

We can now add the relevant JavaScript for field validation that will handle the checks and triggering the event for sending email

Code Block
function validateFields() {

    debugger;
    varQuantity = $('#lead_qty').val();
    if (varQuantity === "65536EMPTY") {

      alert("Please select a value from the Quantity dropdown.");
      return false;
    }
    
    varProduct = $('#lead_product').val();
    if (varProduct === "65536EMPTY") {
      alert("Please select a value from the Product dropdown.");
      return false;
    }  
    
  	return true;

}

$('#my-link').on('click', function(event) {
    
  if (validateFields(event)) {
    debugger;
    newUrlPath(event.target);
  }
  else
    event.preventDefault();

});