检测日期字段套件中的更改

时间:2019-04-01 04:19:22

标签: suitecrm

我正在尝试检测常规“日期”字段中的日期何时更改

已经看过一些论坛文章,介绍如何使用文本字段和下拉菜单来完成此操作,但不适用于日期字段。

也尝试过:

'displayParams'=> 数组( 'javascript'=>'onchange =“ checkStatusOption(this)”', ),

在editviewdefs.php中,但是它不起作用(尽管适用于文本字段)

最接近的实际上是跟踪屏幕上的每次单击,然后检查日期字段的前后状态,但这显然不是一个很好的解决方案

这是扩展的editview中的代码

    function display() {

        parent::display();

        $js = <<<EOT
<script type="text/javascript" language="JavaScript">

        // Capture initial state
        calendar_before = document.getElementById("contract_date_c").value;

       // Wait for any click to take place anywhere on the screen
        $(document).click(function() {

            // Capture state after we clicked somewhere
            calendar_after = document.getElementById("contract_date_c").value;

            // Compare the before and after
            if(calendar_before != calendar_after) {

                // Change detected
                alert("Something's changed eh?" + calendar_before +" "+ calendar_after);
            }

            // Set the new state of the before_calendar
            calendar_before = document.getElementById("contract_date_c").value;


        });

    }

</script>
EOT;

// now I output the javascript
        echo $js;

    }

更新:

我也尝试了建议的解决方案

1)创建了一个文件custom / modules / un_inventory / contract_date_c_change.js并将以下内容放入其中:

function yourCustomFunction(formElement){
    console.log(formElement);
}

2)在元数据文件中包含对该文件的引用(确保已加载):

array (
    'file' => 'custom/modules/un_inventory/contract_date_c_change.js',
),

3)将updateCallback附加到该字段:

    array (
        'name' => 'contract_date_c',
        'label' => 'LBL_CONTRACT_DATE',
        // Checks if this field got filled up and shows hidden form field
        'displayParams' =>
            array (
                'updateCallback' => 'yourCustomFunction();',
            ),
    ),

但是当我更改日期字段时什么也没发生

1 个答案:

答案 0 :(得分:1)

检查此日期(在SuiteCRM 7.11中进行了测试)是否有日期时间字段,其他字段请查看对另一个SO question的答案

首先,在editviewdefs.php中添加您的自定义JS(“帐户”模块示例)

'includes' => 
      array (
        0 => 
        array (
          'file' => 'modules/Accounts/Account.js',
          'file' => 'custom/modules/Accounts/myCustomFile.js',
        ),
      ),

创建自定义JS文件custom/modules/Accounts/myCustomFile.js

function yourCustomFunction(formElement){
  console.log(formElement); 
}

然后使用editviewdefs.php中的以下代码更新要监视更改的字段(在示例中为contractsigned_c):

array (
            'name' => 'contractsigned_c',
            'label' => 'LBL_CONTRACTSIGNED',
            'displayParams' =>
             array (
              'updateCallback' => 'yourCustomFunction(this)',
          ),
          ),

现在在“管理/维修”部分中进行一个Repair and Rebuild并确保它应该起作用:)

如果需要,可以在function display()上添加JS函数,相同的话,该函数将在本机combo update之后立即调用。看起来像这样combo_contractsigned_c.update(); yourCustomFunction(this)