Formula Proper for string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Falerci
    Junior Member
    • Apr 2019
    • 24

    Formula Proper for string

    Hi there,

    I'm looking for the Proper function in Espo Crm. Basically, I would like to capitalize the first letter of each word and put in lower case the rest.

    Based on the Documentation, Espo offers only the following functions:
    • string\lowerCase
    • string\upperCase
    Do you have an idea why Espo doesn't offer this formula?

    Thanks
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    Hi,

    Even javascript doesn't offer these functions. You can utilize string\substring, string\concatenate, string\upperCase to achieve the needed result. You need to concatenate two substrings, the first is only the first letter upper cased, the second is the rest.
    Last edited by yuri; 01-16-2021, 09:01 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

    • item
      Active Community Member
      • Mar 2017
      • 1476

      #3
      Hello,

      ucwords("hello world"); => Hello World
      W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


      PHP Code:
      namespace Espo\Custom\Core\Formula\Functions\StringGroup;
      
      use \Espo\Core\Exceptions\Error;
      
      class Ucwords extends \Espo\Core\Formula\Functions\Base
      {
      public function process(\StdClass $item)
      {
      if (!property_exists($item, 'value')) {
      throw new Error();
      }
      
      if (!is_array($item->value)) {
      throw new Error();
      }
      
      if (count($item->value) < 1) {
      throw new Error();
      }
      
      $string = $this->evaluate($item->value[0]);
      return ucwords( $string);
      }
      } 
      
      https://docs.espocrm.com/development...on-in-formula/

      All info is there
      If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

      Comment

      Working...