Hot answers tagged

19

Create a div with whatever contents you want in the modal, and with a class "modal". Then create a new Garnish.Modal object with it: var $div = $('<div class="modal">...</div>'); var myModal = new Garnish.Modal($div);


6

You can get the Element Select’s JS instance like so: $(document).ready(function() { var elementSelect = $('#your-container-id').data('elementSelect'); }); (Replace your-container-id with whatever ID you passed into the id param when calling forms.elementSelect or forms.elementSelectField.) Then you can attach a selection callback to that: ...


3

Although I agree to close this, I think Anubarak deserves an answer as to why this is not Craft related. The Garnish Modal doesn't care what you use it for, it's just a modal. So, what Daryl and Mats is hinting at, is that you just need to style the content of the modal properly, and you'll have scroll. Which is what you've tried to do with overflow: auto ...


2

To me, this seems like a great use case for a custom dashboard widget.


2

This is an issue with Assets fields if you have a dynamic Subfolder path set on in the field’s settings. It’s been fixed for 2.3 though ;)


2

Foud the answer after digging a bit, in fact I missed a little detail. The base javascript code was correct : $modal = new Garnish.Modal($('#my-modal')); //create a new modal $modal.show(); //shows the modal $modal.hide(); //hides the modal Everything is in the HTML code, you need to declare something like this : <div id="my-modal" class="modal"> &...


2

The BaseElementSelectorModal class takes a second parameter settings, which can include a criteria object. This criteria object is used to create an ElementCriteriaModel on the server, which means it can have any property an ElementCriteriaModel can have – including locale: var currentLocale = Craft.getLocalStorage('BaseElementIndex.locale') || Craft.locale;...


2

This is what I ended up doing: https://github.com/nystudio107/disclosedassets/blob/master/resources/js/disclosedassets.js There is a Garnish.Modal.visibleModal that will contain the handle to the Garnish modal object if one is visible. You can use this to see if a modal is visible, and even see which one. Unfortunately there's no event I'm aware of that ...


2

@Maxime, I had to edit your code slightly, as $.ajax() doesn't accept .success as a chain. $('#login-form').submit( function (e ) { e.preventDefault(); var data = $(this).serialize(); $.ajax({ method: 'POST', url: '/', data: data, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, success: ...


2

You may use some ajax to send your form so your modal will not validate and/or close and your page wont reload. Here's a working example of what you will need to do in JS (this example use jQuery): $('#yourFormId').submit( function (e ) { e.preventDefault(); var data = $(this).serialize(); $.ajax({ method: 'POST', url: '/',...


1

I am developing in Craft 3 and the accepted answer needs some modification to work. I might also be ahead a version of jQuery. Craft 3 looks for the 'Accept' header in the controller to determine if a JSON response is needed. Therefore you need to also send an 'Accept','application/json; charset=utf-8' header to elicit a JSON response from the login ...


1

The easiest solution is to simply hide that DOM element using Control Panel CSS.


1

It looks as if there is no clean way to do this. The solution I am using to detect a new modal is detect double click on the element wait a second until the modal has opened find the modal which is actually open Like this: $('body').on('dblclick', 'div.element.small', function() { window.setTimeout(function(event) { // get our modal (there may be ...


1

If I'm interpreting 'craft.js' correctly, there doesn't seem to be any way to do this, at least not via craft methods. Apart from passing in the initial settings parameter, everything else looks like protected methods. You could potentially do it manually through javascript however by triggering a 'click' event on the elements directly. You would have to ...


1

I copied and modified the built-in craft AccountSettingsForm.js and placed it in my own plugin to test and it seems to work great. You will need to adapt it for your own use of course. It is currently triggered on elements that have a class 'btn confirm', and just prints 'Password Confirmed!' on success to the alert window. Create a button in your plugins ...


1

By default, Garnish.Modal will automatically close other modals when show() is called (which happens automatically when you first create it). That behavior can be overridden by setting the closeOtherModals setting to false, though: var myModal = new Garnish.Modal($container, { closeOtherModals: false });


1

When 'generateTransformsBeforePageLoad' => true is set, is it taking a long time to load because of the sheer number of images you have or is it only on the first request when all of the transforms are being generated? After they are generated, they are quickly served directly by Apache (or whatever your webserver is) and Craft doesn't get involved. If ...


Only top voted, non community-wiki answers of a minimum length are eligible