I’m looking to create a select menu that just contains the count from a Grid field on the same page. So if a Grid field named “blocks” 3 rows, the select menu options would be “1, 2, 3”.
My use case: We need to create dynamic layouts for a home page, based on breakpoint. There are “blocks” of content entered into a Grid field. Then there are 6 other fields (one for each breakpoint) where they can select which blocks appear in which column for that breakpoint. Each of the “block” select menus should have an up-to-date count based on the “blocks” Grid field.
So, my new fieldtype needs to be able to listen to a specific Grid field and update its options when the Grid field changes.
Is this possible?
There is an addRow jQuery event that is triggered when a new row is added. You could listen for that. It’s not documented so you’d have to inspect the Grid JS filed on GitHub to understand how it works.
There are also the events you can bind to, but not sure if that is what you’re looking for. These are mentioned in the EE docs.
Grid.bind('your_addon', 'display', onDisplay);
Grid.bind('your_addon', 'beforeSort', beforeSort);
Grid.bind('your_addon', 'afterSort', afterSort);
// Subscribe to the global event, will trigger for any Grid field on the page
$(document).on('grid:addRow', function (element) {
});
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.