Announcement

Collapse
No announcement yet.

Change color of a field

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

  • Change color of a field

    Delighted to greet you.
    I am working on a project in a company that has hired me. I'm advanced on it but I'm stuck on something that I don't know if it's absurd to ask but I've been searching for information for several days without success.
    I need to change the color of a field in Account when it is more than 0.

    Do you know if this can be done through Formula Sandbox?

    Can you explain to me how to do it?

    thanks and regards​

  • #2
    Hi,

    Define a custom view for your field.

    custom/Espo/Custom/Resources/metadata/entityDefs.json:

    Code:
    {
        "fields": {
             "yourField": {
                  "view": "custom:views/fields/your-field.js
              }
        }
    }
    client/custom/src/views/fields/your-field.js:

    Code:
    define(['views/fields/currency'], FieldView => {
    
        return class extends FieldView {
    
            afterRender() {
                super.afterRender();
                  
                if (this.isReadMode()) {
                    const value = this.model.get(this.name);
    
                    if (value && value > 0) {
                        // Perform DOM manipulation here.
                    }
                }
            }
        };
    });
    Clear cache in Espo.

    Note that I didn't check this code. Mistakes are possible.
    Last edited by yuri; 02-13-2024, 08:26 AM.

    Comment


    • #3
      Thanks for answering.
      The file I want to modify is an account field. In my account.json file it is this:

      Code:
              "saldoVencido": {
                  "type": "currency",
                  "onlyDefaultCurrency": true,
                  "decimal": true,
                  "readOnly": true,
                  "isCustom": true
              },​

      Should I modify something here? What I want is to change the color of the field to red when it is greater than 0​

      Comment


      • #4
        Hey!!!!
        Can someone help me change the color in an account field when it is greater than €0? Yuri's code didn't work for me

        Comment


        • #5
          No need multiple exclamation marks please.

          I provided you with quite enough information to start digging into.

          > Should I modify something here?

          No need to wait for an answer, you could just experiment and see.

          Code:
          {
                  "saldoVencido": {
                      "type": "currency",
                      "onlyDefaultCurrency": true,
                      "decimal": true,
                      "readOnly": true,
                      "isCustom": true,
                      "view": "custom:views/fields/your-field.js"
                  }
          }​
          You are asking for a ready solution. But this is work. To help you I need to hold off my work first. Who will do my work then?
          Last edited by yuri; 02-13-2024, 08:37 AM.

          Comment

          Working...
          X