Is it possible to provide dynamic values for fields other than links? Being able to provide a dynamic list of options for an enum or multi-enum field, for example, would be very useful in my environment.
Dynamic field values: enum, multi-enum, etc.
Collapse
X
-
Hello bandtank
Yes it is possible to determine the options offered in an enum or multi-enum field via javasript coding.
To see an actual example, check this code: https://github.com/espocrm/espocrm/b...pe-list.js#L41
There you can see how the options for the multi-enum field entity-type-list are populated by fetching a list of scopes defined in metadata.
Don't forget though, if you are using Espo 7.2, that the field validation "enhancement", will throw an error unless the metadata "options" definition for your field is set to null.Comment
-
Hello bandtank
Yes it is possible to determine the options offered in an enum or multi-enum field via javasript coding.
To see an actual example, check this code: https://github.com/espocrm/espocrm/b...pe-list.js#L41
There you can see how the options for the multi-enum field entity-type-list are populated by fetching a list of scopes defined in metadata.
Don't forget though, if you are using Espo 7.2, that the field validation "enhancement", will throw an error unless the metadata "options" definition for your field is set to null.Comment
-
You're welcome
Here's a sample of using an Ajax (API) call to load a multi-enum field with a list of roles, that I use in the Chats extension:
Code:setupOptions: function () { Espo.Ajax.getRequest('Role/action/list').then( function (data) { data.list.sort((a, b) => (a.name > b.name) ? 1 : -1); this.params.options = []; data.list.forEach(function(optionObj){ // skip non-user roles for internal chat notifications if(this.name.indexOf('privateChat') > -1 && (optionObj.userPermission === 'no' || optionObj.userPermission === 'not-set') ) { return; } this.params.options.push(optionObj.name); },this); // update the field display after downloaing the options from the database this.reRender(); }.bind(this) ); }
Code:setup: function() { Dep.prototype.setup.call(this); // halt processing to allow the layout manager call to generate a response this.wait(true); this.setupOptions(); }, setupOptions: function () { // use the 'list' layout to determine the fields that can be chosen to filter the collection this._helper.layoutManager.get(this.model.get('entityType'), 'list', (listLayout) => { let layoutArray = []; listLayout.forEach(function(field){ layoutArray.push(field.name); }); this.params.options = layoutArray; this.wait(false); },this); }
Last edited by telecastg; 10-14-2022, 09:22 PM.Comment
-
Wait, a chat extension? Did you release this or is it internal/private? Either way, that's a cool idea and thank you for the code. That is exactly what I want to do.Comment
-
You're welcome.
Here's the link for the Chats extension: https://payhip.com/b/tq62X
It is tested up to 7.1.11 only because I don't want to invest time in trying to make it work with 7.2 until that version is mature enough and the field validation bugs have been fixed, but it should work even with 7.2 on its current state.
-
Comment