Adding custom jQuery validation to SugarCRM editview
I am trying to add a custom jQuery script to the "Accounts" data view header or footer, googling around the world, but cannot find a hook that prints the scripts to the header or footer.
My goal is to add custom validation for my custom fields, but as soon as I add jQuery code, the page stops.
I am pasting the following code into custom/modules/Accounts/metadata/editviewdefs.php
$viewdefs ['Accounts'] = array(
'EditView' => array(
'templateMeta' => array(
'javascript' => '<script type="text/javascript">
$(document).ready(function(){
alert("This is my custom javascript code");
});
</script>',
The screen below is generated above the code.
I am removing the jQuery part as follows
$viewdefs ['Accounts'] = array(
'EditView' => array(
'templateMeta' => array(
'javascript' => '<script type="text/javascript">
alert("This is my custom javascript code");
</script>',
I can see that simple JavaScript code is working fine, but the problem only occurs when I add jQuery code, I tried to add jQuery library before the code above, but that did not solve the problem.
Can someone tell me what I am missing here?
source to share
You also need to wrap js with {literal} tags:
$viewdefs ['Accounts'] = array(
'EditView' => array(
'templateMeta' => array(
'javascript' => '<script type="text/javascript">
{literal}
$(document).ready(function(){
alert("This is my custom javascript code");
});
{/literal}
</script>',
source to share