-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table fields not remembering their Default Values row order #3947
Comments
@brandonkelly Brandon, I'm still seeing this problem, on dev-develop -- just checked again this evening. Nothing's changed in my source definition, and I don't see any settings to alter ordering from the physical order rows are placed on (in Craft CP - My Plugin Settings) If I move a row in the usual way (ordering is critical for this plugin), and save, it flips back to its original position. Old rows do stay in their original positions, so I noticed this first on an added row. But if I move old rows, they also are 'stuck' to their pre-move, and pre-fault, positions. Should be simple, I think -- needed for a beta next week...thanks. |
@narration-sd this bug was specifically for the Default Values setting on Table fields. Is that where you’re seeing it too? I verified that the fix worked. Maybe Composer‘s cache was out of date. Rather than being on |
Fair enough, and thanks for the quick attention. I'll run through your scenarios and come back... |
Ok, I've ditched /vendor and composer.lock, cleared composer caches, set Craft to ^3.1.16 (appropriate actually towards the delivery this is for), cleaned out non-essential plugins, and composer install'd. Moving table rows in my plugin settings still reverts on save. Value changes seem to save fine. Brandon, is there anything I could do that you would imagine to break ordering? I did add some items to this plugin/settings recently, if none of them were in the table. I'm going to try reverting to some earlier version to see if re-ordering starts functioning again... What happens ever when you promise something soonish, and I still have to write that code ;) |
Ok! It's Craft latest or so causing this.
Maybe the fix you put in on this original issue made the breakage? Happy to enter this as a separate issue if not/or if you prefer...and I will go back to using craftcms/cms:dev-master to validate your fix towards release... noting @brandonkelly as never sure how seeing post-closed issue comments works for you |
Implements a better fix for #3947
Once again this issue was specifically for the Default Values setting of Table fields (the custom field type, not to be confused with the It happens because associative arrays are sorted by their keys when saved to the project config, in an effort to reduce merge conflicts / unexpected changes in project.yaml. So when saving an array where the order matters, it should be numerically indexed, rather than associative. You can do that by adding this to your component/model’s if (!empty($this->settingName)) {
$this->settingName = array_values($this->settingName);
} Where |
Ok, I see what you're getting at, but this isn't working, as the Settings model isn't filled in at its init() time, even though I've called parent::init() prior to invoking this code. Should I be doing something in the plugin's own init() that I'm overlooking? (smiling because apparently I got bitten by project config, even while waiting on it here) |
also reverted to 3.1.17 after noticing that, in case influenced though didn't think so. It doesn't. feeling is I need to call something within SettingsModel::init() besides parent::init() to get the values filled in. Rather than probe, guess this time, asking. As this is playing hob with needed gross refactoring of a complex React part ;) Thanks again. Saved by Mexican music, very accomplished, with wit. Like one? |
For plugin settings you could do it from public function setAttributes($values, $safeOnly = true)
{
parent::setAttributes($values, $safeOnly);
if (!empty($this->settingName)) {
$this->settingName = array_values($this->settingName);
}
} |
...makes sense, and does the trick. Thanks very kindly, Brandon - the day is saved. Rest of it anyway, but you know what I mean with an exposure coming up. Here's the lady, considerably intelligent, creative, thoughtful, in case you like it. For the wit, besides the song delivery, just watch the video, right up to the last moment :) Well, two. The second one is kind of a Roma treatment...if the listening is the thing. You might guess I like her. Not least for the great variety of music across the stages of her building. From the German, a true bildungsroman. Cheers, Brandon, and on your good deed for the day. |
Description
Table fields don’t remember changes to the row order in their Default Values setting.
Steps to reproduce
The rows will be saved in the order they were created in, rather than the custom-defined row order.
Additional info
The text was updated successfully, but these errors were encountered: