How to add a field while in edit mode? SugarCRM CE

北慕城南 提交于 2019-12-11 10:03:07

问题


I am using Sugar CRM CE. While in edit view of Opportunities, there is a + button and a - button to add or take away email fields. This allows you to click on the + and add an additional email field while in edit view. How can I add this type of feature to other custom fields? Thanks


回答1:


You search for a way to add n related entries in another module.

There is no out of the box solution to my knowledge.

But I did something similar to integrate multiple fields from another module into a editview to make i.e. a product order faster.

In your case first add a javascript to the {MODULE}/metadata/editviewdefs.php:

$viewdefs[{MODULE}] = array (
  'EditView' => array (
    'includes' => array (
        array (
          'file' => 'modules/{MODULE}/js/selectScript.js'
     )

Into this file modules/{MODULE}/js/selectScript.js you put some javascript to generate the buttons (i.e. by positioning them via jquery after the description field). The script should add all the relevant information into a hidden textfield (i.e. named websites_json) which contains for example JSON like this:

{'websites' : ['www.somethin.it', 'www.somethingelse.com']}

If you have to process this information to create multiple objects in another module you could add a file in (custom/) modules/{MODULE}/Save.php in which you handle the data the javascript created, by creating the related entries. You would access the json for example by $_REQUEST['websites_json']. Then you could do with it what ever needs to be done.

In your case with only websites to add you could simply add a textfield in the main modules vardefs to hold a list of websites. So add this to the vardefs of your module to create the db field:

$dictionary['{MODULE}'] = array(
    'table' => '{module}',
    'fields' => array(
        'websites_json' => array (
            'name' => 'websites_json',
            'vname' => 'LBL_WEBSITES_JSON',
            'type' => 'text',
        ),

The field gets saved automatically. On reentering editview you should recreate the websites list to edit it and in detailview you need to handle the json to display the websites as a list.



来源:https://stackoverflow.com/questions/35098301/how-to-add-a-field-while-in-edit-mode-sugarcrm-ce

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!