检测日期字段suitecrm中的更改

问题描述 投票:0回答:1

我正试图检测日期在常规“日期”字段内的变化

已经看过一些关于如何使用文本字段和下拉列表完成此论坛的帖子,但它不适用于日期字段。

还尝试过:

'displayParams'=> array('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();',
            ),
    ),

但是当我改变那个日期字段时没有任何反应

suitecrm
1个回答
1
投票

检查一下(刚刚在SuiteCRM 7.11中测试)获取日期时间字段,其他字段请查看另一个SO question的答案

首先,在editviewdefs.php中包含您的自定义JS(Accounts模块的示例)

'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)

© www.soinside.com 2019 - 2024. All rights reserved.