Announcement

Collapse
No announcement yet.

Change value on the fly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change value on the fly

    I have a link field in an entity.
    I want to change on the fly the value of another field of my entity when i change the value in the link.
    I tried to add an onchange event in the field view link.js :
    this.listenTo(this, 'change', function (model) {
    ...
    }, this);

    but I don't know how to refer to the other field.
    How can I do that ?

  • #2
    I think the problem is scope. When you are in a field view you only have access to that field, not the entity to which that field belongs. To modify different fields within the same entity you would have to write your code in the entity's detail view.

    I found a simpler way, which is to use the very handy relatively new dynamic-handler feature. https://github.com/espocrm/documenta...mic-handler.md

    I am using it to change field values on the fly for an entity called WorkOrder, see this code snippet below from my script client/custom/src/work-order-dynamic-handler.js.

    The only drawback, in my case, because I am using enhanced dynamic logic to change the background color of the fields based on their values, is that in order for the changes to show up immediately a page reload is required but if you only want to change the value that will not be necessary.

    Code:
            serviceTechIdControlField: function () {
                // limit the choices for status if the Service Tech field is not empty
                if (this.model.get('serviceTechId')) {
                    this.recordView.setFieldOptionList('status', [
                        'Assigned',
                        'Completed',
                        'Canceled'
                    ]);  
                    // if a Service Tech has been selected, and the status was Unassigned, change the status to "Assigned"
                    if(this.model.get('status') === 'Unassigned') {
                        this.model.set('status','Assigned');
                        // persist the change
                        this.model.save();
                        // refresh the page
                        location.reload();
                    }
                } else {
                    // if the Service Tech is erased and the status is Assigned, change it to "Unassigned"
                    if(this.model.get('status') === 'Assigned') {
                        this.model.set('status','Unassigned');
                        // persist the change
                        this.model.save();
                        // refresh the page
                        location.reload();
                    }
                }
            }
    Last edited by telecastg; 01-12-2020, 08:04 PM.

    Comment

    Working...
    X