问题描述
我正在尝试在帐户编辑视图的页眉或页脚中添加自定义jQuery脚本,在Google的所有位置搜索但无法找到在页眉或页脚中打印脚本的挂钩。
I am trying to add custom jQuery script in either header or footer of Accounts edit view, searched everywhere in Google but can't find an hook that prints scripts in header or footer.
我的目标是为我的自定义字段添加自定义验证,但是只要我添加jQuery代码,页面就会停止。
My goal is to add custom validation for my custom fields, but as soon as I add jQuery code the page gets halted.
我在 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>',
以上代码生成以下屏幕。
Above code produces below screen.
我删除了这样的jQuery部分
I remove the jQuery part like this
$viewdefs ['Accounts'] = array(
'EditView' => array(
'templateMeta' => array(
'javascript' => '<script type="text/javascript">
alert("This is my custom javascript code");
</script>',
我看到以下警告
I see following alert
我看到简单的JavaScript代码工作正常但只有在我添加jQuery代码时才出现问题,我尝试在上面的代码之前添加jQuery库但是没有解决问题。
I see that the simple JavaScript code is working fine but problem occurs only when I add jQuery code, I tried adding jQuery library before above code but that did not solve the problem.
有人可以告诉我这里缺少什么吗?
Can someone tell what I am missing here?
推荐答案
你还需要用{literal}标签包装js:
You also need to wrap the 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>',
这篇关于在SugarCRM editview中添加自定义jQuery验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!