如何将SuiteCRM的必填字段转换为可选字段?

时间:2018-03-01 20:34:43

标签: javascript php sugarcrm suitecrm

我有一个字段A(下拉)和一个字段B(文本字段),具体取决于字段A的值 - 字段B变为可选字段,例如:

如果字段A的值是1;然后字段B成为必需,为此我使用SuiteCRM带来的JS函数:addToValidate

但如果字段A的值为0,我应该将字段B转换为可选

在最后一种情况下,我可以使用SuiteCRM的哪些JS功能?

谢谢

1 个答案:

答案 0 :(得分:0)

如果您想要更改是否需要动态字段,请查看Dependency Actions

它们允许您根据自定义Sugar Logic公式的值自动切换给定目标字段的必需状态(true / false)。

根据链接的示例和您的示例,它看起来像这样:

./custom/Extension/modules/<module>/Ext/Dependencies/fieldB_required.php

<?php
    $dependencies['<module>']['fieldB_required'] = array(
        'hooks' => array("edit"),
        //Trigger formula for the dependency. Defaults to 'true'.
        'trigger' => 'true',
        'triggerFields' => array('fieldA'),
        'onload' => true,
        //Actions is a list of actions to fire when the trigger is true
        'actions' => array(
            array(
                'name' => 'SetRequired', //Action type
                //The parameters passed in depend on the action type
                'params' => array(
                    'target' => 'fieldB',
                    'label'  => '<field label>', //normally <field>_label
                    'value' => 'equal($fieldA, 1)', //Formula
                ),
            ),
        ),
    );

fieldA是一个字段,当更改时,触发重新评估公式,并设置目标 目标 / em>字段fieldBequal($fieldA, 1)的值。

注意:

  • 虽然在PHP文件中定义了依赖关系动作,但您提供的公式通常在客户端/ javascript端执行,因此无需编写自定义JavaScript代码。
  • 这是一个SugarCRM功能,但它已经很老了,所以SuiteCRM希望仍然支持它。