I have a custom module where in the managerial interface, the user can select products from a Grid (rendered in a modal) to add to a list specific to the Module's functionality. This part is working great!
I am encountering a bit of a weird issue with how the serializer works in that I can't seem to figure out how to "reset" it along with the Grid. This is a very simple problem but hard to explain, so bear with me!
Steps to reproduce:
User opens Product Chooser Modal Window and selects a few products (for example, lets say product ids 8, 10 and 15 are selected) via the checkboxes in the grid. The user clicks "Add Products" and the products are added to their list, the modal window closes. All good.
The user needs to add another set of products, so they re-open the modal window. I programmatically reload the Grid before the modal appears, and manually empty the serializer's hidden
selected_products
input before the modal window is rendered, as so:var varienGrid = this.getVarienGridJsObject(), serializerInput = $('input[name="selected_products"]'); // logs "8&10&15" i.e., previously selected product id's console.info('before grid reload products', serializerInput.val()); // reload the grid with empty params as to not re-select products varienGrid.reloadParams = {}; varienGrid.reload(); // attempting to "reset" the serializer by null'ing the input field serializerInput.val(null); // now this will log out empty, which is intended console.info('after grid reload products', serializerInput.val());
Now the Grid is reloaded for the User to select their new set of products to add to the Module's product list. However, as soon as the select a single product in this freshly loaded grid, the serializer input field "magically" contains all of the previously selected product ids! So if the user selected product id "20", the serializer's input would contain "8&10&15&20" i.e., the new selection, plus all of the product id's selected before the Grid was reloaded and the hidden input was emptied.
What I've Tried
Aside from the above "solution" that didn't end up working, I dug into the varienGrid
JS object and found that in the setCheckboxChecked
method a callback is invoked which is, as far as I can tell, what handles updating the selected_products
input field with new values, as commenting this callback out results in the input field not getting updated. I thought the solution would be to override the getCheckboxCheckCallback
method to provide my own method (e.g., MyJsObject.handleCheckboxChange
) in my Grid class which extends Mage_Adminhtml_Block_Catalog_Product_Widget_Chooser
but doing so still results in the hidden field being updated.
Any help regarding how to "reset" the Mage_Adminhtml_Block_Catalog_Product_Widget_Chooser
serializer would be awesome, thank you and please let me know if I can clarify anything or provide any additional information!