In submit function I am not able to get any proper data related to the file which I am. Here is the theme code, it belongs in your theme’s template. I want to upload a file and I have to use form element type as 'file'. Write an Ajax callback to process the input and respond. Here is an outline of the steps: Add property ajax to a form element in your form array, to trigger an Ajax response. '#title' => t('Example select with attributes'), Forms that use the Drupal Form API (see the Form API topic for more information about forms) can trigger AJAX responses. Here is an example of a select element with some custom classes, a disabled attribute and a data attribute: 'true', The disabled individual elements have come handy on quite a lot of sites. For example, custom classes per option, and disabled individual options in a select element. While working on implementing this, I soon realized that this could be used for much more than just adding data attributes to the options. Here is an outline of the steps: Add property 'ajax' to a form element in your form array, to trigger an Ajax response. In this case we needed to overwrite the basic theme_select function with our own, and make that function call our own function that will create the option elements. Forms that use the Drupal Form API (see the Form API topic for more information about forms) can trigger AJAX responses. In Drupal, many theme functions can be overridden by a custom theme’s own implementation. The Form API doesn’t have functionality to add anything else than the key and the value to the select options… At least, not without some theme function override wizardry. So this should be easy, right?Īfter a frustrating 20 minutes, I found out that this couldn’t be currently accomplished. The form in question was already from our custom module, created via the Drupal Form API. I thought that it would be a walk in the park. Basically I needed to add extra data attributes to select option elements, and access these options via JavaScript when a user clicks the option. In the topic: How to add any kind of attribute (class, disabled, data attributes, etc…) into a Drupal Form API form.Ī while ago I had a task on creating some jQuery magic regarding select options. Drupal 7 Form API select element option attributes
0 Comments
Leave a Reply. |