1

When using createElementSelectorModal() in a plugin, how do you make your source list show items from the current locale selected in the CP? It only seems to show the items from default locale no matter what locale you have selected.

1 Answer 1

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;

var modal = Craft.createElementSelectorModal('Entry', {
    criteria : {
        locale : currentLocale
    }
});
5
  • Can you get the CP's currently selected locale form the js Craft class?
    – a-am
    Mar 21, 2016 at 16:46
  • Yeah - its in the answer above; Craft.locale Mar 21, 2016 at 16:49
  • That only grabs the CP's locale not the currently select locale in the edit entry view.
    – a-am
    Mar 21, 2016 at 16:49
  • 1
    @aran Sorry, didn't understand that you were looking for the current element index locale. The easiest (only) way I know how to do that, is to look in localStorage – just updated my answer. Mar 21, 2016 at 17:06
  • It appears the only way to get the current selected locale from an entry edit screen is via the local hidden input, which is not the same as BaseElementIndex.locale.
    – a-am
    Mar 29, 2016 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.