2

First off all I'm rather new with Drupal & Drupal Commerce. I'm going to do my best to describe what I have done and tried.

I'm developing a website where people can register (buy) a place in event. One of the things is that on the "add to cart" page they should be able to give some information like name, club, etc.

I added some fields to the line item "Product" like for example a textfield name Club and where I selected the option "Include this field on Add to Cart forms for line items of this type" so that it is shows in my add to cart form.

The problem I now have, is that I want (for a start) autocomplete that line-item field Club using #ajax and a ajax callback.

I started off with a hook_form_alter. I dumped (after checking the form id) the $form variable (with dpm()) to look for the Club #textfield so that I can modify it to include #ajax or #autcomplete_path, but I can't find that element.

The only thing I see is an array line_item_fields containing field_club, field_name (my fields that I attached to the line item) of the type #container (and I looked for a #texfield node within it, but didn't find it). I tried adding #ajax to it but that didn't work.

To be honest I'm totally stuck now as I don't know how to proceed further with this. Is it even possible to attach #ajax or any other attributes to a line-item field visible in the add to cart form ?

1

If you change the field from a simple text field into an entity reference field, you can create the different clubs as nodes (seems to make sense, since you could then write info about each club on your site). Entity reference comes with a built in autocomplete.

You could also use taxonmy terms and taxonomy reference field instead if you don't want to create a node for each club. Either way should work just fine, as both have autocomplete built in.

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.