Blocks by Ajax and Magic Data IntegrationBrowser Info Environment
I have bought Blocks by Ajax, as well as Magic Data, Magic Data On Block Load, and Magic Data Forms.
I need to have a page with a combo and a gallery.
1. The combo will present a list of filesets
2. On change on the combo, I want to reload the gallery by Ajax, and to show the selected gallery.
For now, I succeed in :
- modify the fileset in the gallery, using Magic Data On Block Load
- load the gallery using Blocks by Ajax
But I have problem to :
- force the reload when my combo is modified,
- pass the selected value to my gallery block.
Can you help please ?
Thanks in advance,
OPTION 1. Use the BB AJAX remote control block and set it to: request the ajax reload on a form submit of the form containing your user selector; to pass the form parameters to the ajax loading gallery block.
OPTION 2. Use the BB AJAX remote control block and set it to request the ajax reload on the blocks by ajax event. Use some MD on the page to then attach a trigger for the blocks by ajax event when the selection changes. The symbols you want are in the Blocks by Ajax group and will also pass through the selection to the ajax loading gallery block.
You can then access those form parameters in the MD that decides what gallery to load. The MD symbols with BB AJAX include symbols for retrieving form values from Get or Post data.
For the future, I have a Sorcerer's Gallery block currently in the PRB that provides a number of gallery and slider templates where the files to show are selected by Magic Data. It works exactly the same as Sorcerer's Map or Uber List, but shows a gallery. Once released, it will remove the need to use On Block Load for this sort of application.
Thanks again for your help.
To get started, its probably easiest to experiment with loading an HTML block by ajax triggered from your user selector(ie use an html block in place of the gallery to practice)
For the first option, add a remote control block and set the repeat loader to 'when a form is submitted'. This will look for the html form element containing your user selector and trigger a blocks_by_ajax browser event when the form submit button is clicked (and block the normal form submission).
If there is only 1 form on the page and only one block by ajax on the page, that is all you need to do.
Then in the ajax loaded HTML block, add some magic data to display the value of the select by reading it from get or post using FROM_POST_DATA or FROM_GET_DATA.
Once you have it working with an HTML block to just echo your selected user, you can then do the same with your gallery.
Advanced - only for when the above is working:
Again, once the basic mechanism is working you then modify the triggering using Magic Data to catch changes in the user selector rather than submissions of the form, so creating an 'submit on select' behaviour. The MD command AUTO_TRIGGER_BLOCKS_BY_AJAX can be used to connect the select change to the ajax load.
I will experiment this in the next hours, and let you know.
I tried option 1. Seems to be close to work but :
1. I cannot unselect the "include any form inputs with the AJAX data" checkbox. It remains checked whatever I do. I do not mind, since I want my posts with the AJAX data, but I do not understand why. Is it normal ?
2. It works for the first form submission, but, even if the "Render a repeatable AJAX loader" is checked, and set with "repeat loading whenever a form is submitted", I cannot submit the a second time :
- The button is clickable when I load the page : OK
- When I click the button the block is loaded via AJAX : OK
- The button is clickable : OK
- when I click the button, nothing happens and the button remains disabled and non clickable after the click : NOT OK
I will try option 2, but do you have any idea of what I should have missed ?
I add that info :
- I run Concrete 5.6.3, BBA 184.108.40.206, MDOBL 1.0.2, MD 2.9.2
- Chache is totally disabled for now
thanks for your help
I also tested and can confirm that the responder for the blocks_by_ajax
browser event is still working OK, so option 2 will work.
I confirm v3.0.2 fix this issue. Great job.
A last question, which MD symbol should I use to have a "like" operator. I want to filter the list of filesets according to their name (get all filsets which have a fileset name starting by a specific string). Is it possible ?
Another MD user has expressed an interest in such string tests, so I have marked down some ideas for the next update of the symbols addon. I have some other addon updates to do first, so if you need it urgently you could write your own symbol. It should be fairly easy to take one of the existing comparison symbols and hack it.
To start you copy and rename into
Make sure to prefix with your own name, so it won't clash with anything that gets added to MD later.
The main thing users get caught on is that MD only scans for new symbols when you load the dashboard symbol tester!
There is documentation about writing a symbol on the MD symbols docs page on c5 and on c5magic.co.uk.
I also have some symbols for regex matching destined for the next update to Black Magic Data - its virtually impossible to fully sanitize a regex, so a faulty regex could break a site, hence they need to be in Black magic Data.
But for now, I have the behaviour I want using some specific MD symbol, that returns the fileset list I exactly want.
I think that Magic Data is not easy to set at a glance, but very powerfull as soon as you understand exactly what it does and how it works.
Good job, really.
At the moment it is in the PRB, so I have attached a zip (link above) you can download.
I am trying it right now !