Dropdown element does not handle datatype int , and not showing labels.

Status
Not open for further replies.

PaulV888

Member
Hi, I have numerous dropdowns that are setup with numeric key values and are defined as an INT in the db.

These do not show labels anymore after upgrading.

Front-end
upload_2023-3-12_1-58-22.png

Setup
upload_2023-3-12_1-58-41.png


DB
upload_2023-3-12_3-0-51.png



Can we fix this by converting the search value in components/com_fabrik/model/elements.php/getLabelForValue to a string? Which seems to be working.

PHP:
    public function getLabelForValue($v, $defaultLabel = null, $forceCheck = false)
    {
        /**
         * $$$ hugh - only needed getParent when we weren't saving changes to parent params to child
         * which we should now be doing ... and getParent() causes an extra table lookup for every child
         * element on the form.
         * $element = $this->getParent();
         */
        $params = $this->getParams();
        $values = $this->getSubOptionValues();
        $labels = $this->getSubOptionLabels();
-->        $key    = array_search(strval($v), $values, true);


Or should I convert all integer dropdowns to varchar?

Thanks,



Fabrik 4 Gamma2
Joomla! 4.2.8 Stable
PHP Version 8.1.2-1ubuntu2.10
Apache/2.4.52
MySql: 8.0.32
 
It's a bit a corner case because Fabrik created dropdown columns are TEXT (and every time when you save a dropdown linked to an INT column it's trying to change it to TEXT).

I don't think this is the correct place, an int value may be used in other cases and array_search is explicitly setting strict=true.
Better do it in dropdown.php, add
Code:
        /**
     * Used by elements with sub-options, given a value, return its label
     * Fabrik dropdown value is string. In case of linking to external tables with int column force $v to string
     *
     * @param   string $v            Value
     * @param   string $defaultLabel Default label
     * @param   bool   $forceCheck   Force check even if $v === $defaultLabel
     *
     * @return  string    Label
     */
    public function getLabelForValue($v, $defaultLabel = null, $forceCheck = false)
    {
        return parent::getLabelForValue((string)$v, $defaultLabel, $forceCheck);
    }
 
Last edited:
Nice! Thanks. That works.

Yeah, I understand its a corner case, introduced by my old DB and my stubbornness not to allow Fabrik "Alter Field Types"

Having a TEXT field as index for a type DropDown is ok and I wouldn't mind converting those. I wouldn't want to do that for dbjoins for performance reasons.
 
Dbjoins (with value =id[recommened]) are INT columns.

So I think to support dropdown int values in case of linking to such tables or views is ok.
But it's up to the admin to set "Alter field types..." etc.

Edit:
Added to next release
 
Last edited:
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top