Menu

Fields with predefined values

2020-10-23
2020-10-23
  • Oscar Barraza Aravena

    From the problems module we create the projects module with a series of fields necessary for our operation, but the following drawbacks arise:
    How to set the default value of the service and subcategory fields to the appropriate value for projects (Project in both cases).
    How to change the color of the progress bar in the "progress" field, as it currently shows green at the lowest values and red at the highest, being that it should be the other way around in our case.
    When no value is selected for the horizontal radius selection fields this shows the value "not defined" when it would be preferred not to show any value.

     
  • Molkobain

    Molkobain - 2020-10-23

    Hello Oscar,

    Default value
    You should take a look at the "Form Prefill" feature, it allows you to pre-select a value for some fields, check here.

    Progress bar colors
    This cannot be done natively, the only way to do this for now is to extend the standard "AttributePercentage" with your own class and to define the thresholds / colors. You can take a look at the existing class, below is an example of a class extending it:

    class AttributePercentageCustom extends AttributePercentage
    {
        public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
        {
            $iWidth = 5; // Total width of the percentage bar graph, in em...
            $iValue = (int)$sValue;
            if ($iValue > 100)
            {
                $iValue = 100;
            }
            else
            {
                if ($iValue < 0)
                {
                    $iValue = 0;
                }
            }
            ///////////////////////////////
            // BEGIN THRESHOLDS CHANGE HERE
            ///////////////////////////////
            if ($iValue > 90)
            {
                $sColor = "#cc3300";
            }
            else
            {
                if ($iValue > 50)
                {
                    $sColor = "#cccc00";
                }
                else
                {
                    $sColor = "#33cc00";
                }
            }
            /////////////////////////////
            // END THRESHOLDS CHANGE HERE
            /////////////////////////////
            $iPercentWidth = ($iWidth * $iValue) / 100;
    
            return "<div style=\"width:{$iWidth}em;-moz-border-radius: 3px;-webkit-border-radius: 3px;border-radius: 3px;display:inline-block;border: 1px #ccc solid;\"><div style=\"width:{$iPercentWidth}em; display:inline-block;background-color:$sColor;\">&nbsp;</div></div>&nbsp;$sValue %";
        }
    }
    

    Overloading "not defined"
    Again, no native way to do this properly.

    The only to do this, but I don't recommand it, is to overload the "GetAsHtml()" method of your class and to a dedicated processing for this particular attribute code. The reason why I don't recommand this is because if another extension wants to overload this method as well, you will have a conflict and only 1 extension will work.

    Hope this helps,
    Guillaume

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.