添加自定义字段到编辑视图 - SugarCRM [英] Adding Custom Field to Edit View - SugarCRM

查看:29
本文介绍了添加自定义字段到编辑视图 - SugarCRM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改 SugarCRM (SugarPro 6.1.2) 实例的 EditView 中自定义字段(复选框)的行为.具体来说,我希望每当有人单击复选框时都会显示一个 div.该字段按预期出现在编辑"视图中,我添加了一些执行 onclick 的 javascript - 这也很好用.问题是,当记录被保存时,复选框的值没有被保存.以下是我如何添加字段和关联 javascript 的细节:

I am trying to modify the behavior of a custom field (a checkbox) in the EditView of a SugarCRM (SugarPro 6.1.2) instance. Specifically, I would like a div to be exposed whenever someone clicks on the checkbox. The field appears in the Edit view as expected and I have added some javascript that executes onclick - this works fine too. The problem is that, when the record is saved, the value of the checkbox is not saved. Here are specifics on how I went about adding the field and associating the javascript:

  1. 我在 Studio 中将该字段创建为复选框.它叫做 wire_payment_c
  2. 我将该字段添加到 DetailView 和 EditView 布局中.
  3. 我运行了 Quick Repair &重建
  4. 我编辑 ./custom/modules/MODULE/metadata/editviewdefs.php 如下:

  1. I created the field as a checkbox in Studio. It's called wire_payment_c
  2. I added the field to the DetailView and EditView layouts.
  3. I ran Quick Repair & Rebuild
  4. I edited ./custom/modules/MODULE/metadata/editviewdefs.php as follows:

  1 => 
array (
  0 => '',
  1 => 
  array (
    'name' => 'wire_payment_c',
    'label' => 'LBL_WIRE_PAYMENT',
 'customCode' => '<input type="hidden" value="0" name="wire_payment_c">    
 <input id="wire_payment_c" type="checkbox" tabindex="107" title="" value="{$fields.wire_payment_c.value}" name="wire_payment_c" onclick="showMe(\'wire_message\', this)"> 
 <div id="wire_message" style="display:none">Please obtain wire payment information.</div>' ,
  ),
),

在面板定义的正下方,我还添加了以下内容:

And just below the panels definition, I added the following also:

'includes'=> array(
     array('file'=>'custom/modules/MODULE/wire_pmt.js' ),
 ),

  1. 我在 ./custom/modules/MODULE/wire_pmt.js 创建了包含 showMe() 的 javascript.
  2. 我运行了 Quick Repair &再次重建

如果我取出 editviewdefs.php 中的 customCode 行,我已经能够验证复选框值是否完全按预期保存并保留在数据库中.此外,我可以验证删除 onclick 指令并简单地将 input 标记保留在分配给 customCode 的值中就足以重现问题.结果似乎是这个问题与 javascript 无关 - 它与我如何重新渲染输入标签有关.但是我为 input 标签准备的代码看起来与我完全注释掉 customCode 并通过 FireBug 查看表单时看到的完全一样.

I've been able to verify that the checkbox value is saved and retained in the database exactly as expected if I take out the customCode line in editviewdefs.php. Further, I can verify that removing the onclick directive and simply leaving the input tag in the value assigned to customCode is enough to reproduce the problem. Upshot seems to be that this issue has nothing to do with the javascript - it's something about how I am re-rendering the input tag. But the code I have in place for the input tag looks exactly like what I see when I comment out customCode altogether and view the form through FireBug.

在这种情况下,是否还需要做其他事情才能让 Sugar 将自定义字段的值保存到数据库中,然后在加载时将保存的值显示到详细信息和编辑视图中?很高兴阅读有关此过程的文档,但未能找到任何似乎适用于此类特定任务的文档.

Is there something else that one has to do in a situation like this to get Sugar to save the value of custom fields to the database and then display the saved value to the Detail and Edit Views on load? Happy to read docs on this process, but have been unsuccessful in finding any that seem to apply to this specific sort of task.

非常感谢!

推荐答案

在调查您的问题时,我发现问题在于您如何确定是否选中了复选框.这会影响提交表单的方式.

In investigating your issue, I found that the problem is how you are determining if the checkbox is checked. This is affecting the way the form is being submitted.

目前您正在使用:value="{$fields.wire_payment_c.value}"

属性值默认为1.使用 checked 属性指定复选框是 true 还是 false 的决定因素.

The attribute value should by default be 1. The determining factor in whether the checkbox is true or false is specified with the checked attribute.

您的 customCode 属性应该更像这样:

Your customCode attribute should look more like this:

'customCode' => '<input type="hidden" value="0" name="wire_payment_c">{if $fields.wire_payment_c.value == "1"}{assign var="isChecked" value="CHECKED"}{else}{assign var="isChecked" value=""}{/if}<input type="checkbox" id="wire_payment_c" name="wire_payment_c" value="1" title="" tabindex="107" onclick="showMe(\'wire_message\', this)" {$isChecked}><div id="wire_message" style="display:none">Please obtain wire payment information.</div>',

要了解我们如何在核心产品中处理此问题,您可以查看 include/SugarFields/Fields/Bool/EditView.tpl.

To see how we handle this in the core product, you can take a look at include/SugarFields/Fields/Bool/EditView.tpl.

亲切的问候,杰瑞·克拉克

Kind regards, Jerry Clark

开发者支持工程师

这篇关于添加自定义字段到编辑视图 - SugarCRM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆