I'm writing plugin to extend Craft Commerce and I want to present a good way to select products in CP.

I know I could use dropdown select for this, but using Craft's elementSelect would make the UI much nicer. Is there a way to use elementSelect dialog / fieldtype not just for entries or assets, but for custom data set (in my case, Commerce Products)?


If you are referring to a custom field to select products, one already exists:

screenshot of product field type

If you are building a general attribute field for a plugin, taking a look at the B BaseElementFieldType.php within the craft/app filder (that the product field above extends) will give you clues on how to recreate the UI to select products (or any other element).

The key file being craft/app/templates/_includes/forms/elementSelect.html which will show you how to instantiate the Craft.BaseElementSelectInput js class.

Hope that points you in the right direction. I am not sure if there is a full guide out there on how to useCraft.BaseElementSelectInput js, but hopefully the above will get you most of the way there by looking at the code.

  • Thanks Luke - do you perhaps know any way to use Commerce Product fieldtype directly in my plugin? That would be the best way around probably. May 7 '16 at 5:24
  • 1
    Take a looks at craftcms.stackexchange.com/questions/895/… May 9 '16 at 20:32
  • 1
    If you want to use the fieldtype you would need to make your record an element type in craft to allow custom fields to be added to it. May 9 '16 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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