Search
Other Articles Field questions
Forum

Articles Field issue when saved out of view in dev version

Andrea Malalana's Avatar Andrea Malalana
Hey there, we talked about this before, but as I've been needing to "fix" this issue in my code in multiple places, I figured I'd post it here to see if you find a more permanent solution.

Basically, with the latest version of Articles Field, where you introduced the ajax loading for faster loading only when the input is in view, an issue araised:

- Have an Articles Field inside a Subform
- Make sure it can have multiple values
- Select multiple values in it and save
- If you save while it's in view, all it's fine, it gets saved in the db json correctly as array with multiple elements:
["15299","15416"]
- If you save it while it's NOT in view, it gets saved in the db json wrong, as a single array element and comma separated string:
["15299,15416"]

While this doesn't cause issues with the default field output - which uses the ->value, this causes issue when trying to use the ->rawvalue in custom code - as the rawvalue is not an array as it should be, in the second broken case.

In my code I keep fixing it with a function like this:
// Fix faulty syntax that may get saved if the field is not in view
self::fixArticlesFieldRawValue($subform_row['wrestler']->rawvalue);

    public static function fixArticlesFieldRawValue(&$rawvalue)
    {
        if ( ! is_array($rawvalue))
        {
            return $rawvalue;
        }

        // If the first element of the array contains a comma, split it
        if (strpos($rawvalue[0], ',') !== false)
        {
            $rawvalue = explode(',', $rawvalue[0]);
        }

        return $rawvalue;
    }

But as it's starting to become lots and lots of places where I need to apply this, it would be great if you could fix it on the extension itself (either by saving the rawvalue correctly in the json, or by manipulating the object that gets generated from the json)
Peter van Westen's Avatar Peter van Westen ADMIN
Please try the latest development version from:
regularlabs.com/development-releases
Please post a rating at the Joomla! Extensions Directory
Andrea Malalana's Avatar Andrea Malalana
Not working for me. If you save the field while not in view, both the saved json value in the database and the subform_row->rawvalue in the object are still a single array with a string:

Saved value in the db:
"field73":["15489,15287,15204,15500,15505,15292,15552,15303,15405,15511,15291,15525,15527,15529"]

subform_row->rawvalue in the object:
[rawvalue] => Array
        (
            [0] => 15489,15287,15204,15500,15505,15292,15552,15303,15405,15511,15291,15525,15527,15529
        )
Peter van Westen's Avatar Peter van Westen ADMIN
Please try the new development version.
Please post a rating at the Joomla! Extensions Directory
Andrea Malalana's Avatar Andrea Malalana
Still no luck, still same exact as previous post 🙁
Peter van Westen's Avatar Peter van Westen ADMIN
Ok, not easy this. As Joomla lacks a good way to adjust the form data that is being saved.
New dev version.

Make sure the Regular Labs system plugin is ordered AFTER the Fields system plugin.
Please post a rating at the Joomla! Extensions Directory
Andrea Malalana's Avatar Andrea Malalana
Bingo! With the latest dev version AND with the Regular Labs Library plugin order AFTER the Fields plugin, it works now.
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription