Just for information :
When copy > past from forum, something add some special char, you need to remove theses special char else the code don’t work.
It seems the requester have this issue
Dynamic related fields
Collapse
X
-
This might helpSo i in the opportunities entity I related a Products entity, from which I created a few related fields, like product weight and price.
Is there a way to make these related fields appear as I select the product record? Because right now they only appear when I hit the save button.
I have websocket enabled and working.
-
Hello, in the path, select the file Opportunités.json
custom/Espo/Custom/Resources/metadata/entityDefs
--------PHP Code:"products ": { "type": "link", "view": "custom:views/fields/profil", "isCustom": true }, "opportunités": { "readOnly": true, "type": "foreign", "link": "products", "field": "name", "view": "views/fields/foreign-varchar", "isCustom": true },
and add this file to the path.
PHP Code:define('custom:views/fields/profil', ['views/fields/link', 'helpers/record-modal'], function (Dep) { return Dep.extend(/** @lends module:views/fields/link.Class# */{ _foreignLinksAttributeHashMap: [], setup: function () { console.log("custom:views/digital-imaging-qa-qc-record/fields/digital-imaging-qa-qc-protocol this.model = ", this.model); Dep.prototype.setup.call(this); //setup foreign link hash map this._setupForeignLinkHashMap(); // reRender the foreign field views anytime the link change event fires this.listenTo(this, 'change', () => { this._foreignLinksAttributeHashMap.forEach(function (obj, index, array) { let fieldView = this.getParentView().getFieldView(obj.entityFieldName); if (fieldView.isRendered()) { fieldView.reRender(); } }, this); }); }, /** * Select. * * @param {module:model.Class} model A model. * @protected */ select: function (model) { this._foreignLinksAttributeHashMap.forEach(function(obj,index,array) { let fieldView = this.getParentView().getFieldView(obj.entityFieldName); fieldView.model.set(fieldView.name,model.get(obj.linkFieldName),{silent:true}); },this); Dep.prototype.select.call(this,model); }, /** * Clear. */ clearLink: function () { this._foreignLinksAttributeHashMap.forEach(function(obj,index,array) { let fieldView = this.getParentView().getFieldView(obj.entityFieldName); fieldView.model.unset(fieldView.name,{silent:true}); },this); Dep.prototype.clearLink.call(this); }, _setupForeignLinkHashMap: function () { let thisObj = this; thisObj._foreignLinksAttributeHashMap = []; thisObj.mandatorySelectAttributeList = this.mandatorySelectAttributeList || []; //get list of foreign fields of the entity this field belongs to $.each(this.getMetadata().get(['entityDefs', this.entityType, 'fields']), function (entityFieldName, entityFieldAttributes) { if ('type' in entityFieldAttributes && entityFieldAttributes.type === 'foreign' && 'link' in entityFieldAttributes && entityFieldAttributes.link === thisObj.name && 'field' in entityFieldAttributes) { thisObj._foreignLinksAttributeHashMap.push({ entityFieldName: entityFieldName, linkFieldName: entityFieldAttributes.field }); thisObj.mandatorySelectAttributeList.push(entityFieldAttributes.field); } }); }, }); }); Leave a comment:
-
Dynamic related fields
So i in the opportunities entity I related a Products entity, from which I created a few related fields, like product weight and price.
Is there a way to make these related fields appear as I select the product record? Because right now they only appear when I hit the save button.
I have websocket enabled and working.
Tags: None

Leave a comment: