Zeka Posted January 12, 2020 Share Posted January 12, 2020 Hi. Is it possible to set matrix/repeater item collapsed/uncollapsed state via API? Currently I set 'Repeater item visibility in editor' setting to 'Items always open (disables dynamic loading for existing items)' , but it more like a workaround than a solution. Thanks, Eugene. Link to comment Share on other sites More sharing options...
Robin S Posted January 13, 2020 Share Posted January 13, 2020 (edited) 18 hours ago, Zeka said: Is it possible to set matrix/repeater item collapsed/uncollapsed state via API? Sort of. This does the job but is somewhat hacky: $wire->addHookBefore('InputfieldRepeater::render', function(HookEvent $event) { $inputfield = $event->object; $session = $event->wire('session'); // Existing open IDs from core (e.g. items that contain errors) $existing_open_ids = $session->getFor('InputfieldRepeater', 'openIDs') ?: []; // Find the IDs of items you want to render in open state $open_ids = $inputfield->value->find("images.count>1")->explode('id'); // Merge IDs $open_ids = array_unique(array_merge($existing_open_ids, $open_ids)); // Set open IDs to session $session->setFor('InputfieldRepeater', 'openIDs', $open_ids); }); $wire->addHookBefore('InputfieldRepeater::processInput', function(HookEvent $event) { // Clear open IDs from session $event->wire('session')->removeFor('InputfieldRepeater', 'openIDs'); }); Would be nice to have a proper API method to do this. Edited January 13, 2020 by Robin S Code tweak 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now