Announcement

Collapse
No announcement yet.

Formula Proper for string

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

  • 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

  • #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.

    Comment


    • #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

      Comment

      Working...
      X