0

Change a field alignment in script

Hello friends,

I can't figure this thing out. Is it possible to change the alignment of a formula field to right aligned inside a script without using HTML, CSS and the Style window.

I have a formula field calculating age based on another field that is Date type. I am using the styled() function to change the background of this field to "light grey" color to make it look like disabled. Since styled() returns a styled object, the alignment changes to "left aligned" and since age() returns a number, so I want the formula field to have the result "right aligned".

let age := 0;
if 'Date of Birth' != null then
    age := age('Date of Birth')
end;
styled(text(age), "#F7F8FC")

4 replies

null
    • Fred
    • 4 mths ago
    • Reported - view

    There is a style section for formula fields and you can set alignment.

     

    Is that what you want?

      • Database App Developer
      • vermau81
      • 4 mths ago
      • Reported - view

       No, I don't want to use the Style. I want to use the code to right align in a formula field. If there is no function to achieve this through the code then I will use the Style sheet of course (but that's for last).

      Basically I want to be able to change the background in runtime through code rather than in the beginning based on Style popup.

      • Sean
      • 4 mths ago
      • Reported - view

       I don't think it's possible to apply a style in script like you want without using the html() function. It would be nice if Ninox added an alignment parameter to the styled() function, but you probably don't want to wait around for it. I would just leave the Age formula as age('Date of Birth') and then have CSS in a Formula field. You could apply different colors conditionally.

      switch true do
      case Age < 20:
          html("
      <style>
          .form .component:nth-child(4) .stringeditor-fn {background-color: red;}
      </style>
      ")
      case Age < 40:
          html("
      <style>
          .form .component:nth-child(4) .stringeditor-fn {background-color: green;}
      </style>
      ")
      default:
          html("
      <style>
          .form .component:nth-child(4) .stringeditor-fn {background-color: blue;}
      </style>
      ")
      end
      
      • Database App Developer
      • vermau81
      • 4 mths ago
      • Reported - view

       This is amazing Sean, thanks for the code. I wish Ninox adds the alignment parameter to either "styled()" function or provide an "align" property to the formula fields in the new version 3.13

      That ways we can change the alignment at runtime without any external coding (HTML and CSS).

Content aside

  • Status Answered
  • 4 mths agoLast active
  • 4Replies
  • 47Views
  • 3 Following