Change color of a field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smachado
    Junior Member
    • Feb 2024
    • 14

    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​
  • yuri
    Member
    • Mar 2014
    • 8453

    #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.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • smachado
      Junior Member
      • Feb 2024
      • 14

      #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

      • smachado
        Junior Member
        • Feb 2024
        • 14

        #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

        • yuri
          Member
          • Mar 2014
          • 8453

          #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.
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          Working...