2

I can quite easily add ajax autocomplete properties to a regular textfield using the code below, but it doesn't work when I change the field to type webform_email. Is it possible to do?

function flower_order_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'webform_client_form_68911') {
        //Add autocomplete fields for manager username
        $form['submitted']['name_of_authorising_manager']['#autocomplete_path'] = 'user/autocomplete';  
    }
}

Here's the dpr output for the relevant field in the form:

Array
(
    [#type] => webform_email
    [#title] => Name of authorising manager:
    [#title_display] => inline
    [#default_value] => 
    [#required] => 1
    [#weight] => 4
    [#description] => 
    [#attributes] => Array
        (
            [class] => Array
                (
                    [0] => email
                )

        )

    [#element_validate] => Array
        (
            [0] => _webform_validate_email
        )

    [#theme_wrappers] => Array
        (
            [0] => webform_element
        )

    [#translatable] => Array
        (
            [0] => title
            [1] => description
        )

    [#webform_component] => Array
        (
            [nid] => 68911
            [cid] => 18
            [pid] => 0
            [form_key] => name_of_authorising_manager
            [name] => Name of authorising manager:
            [type] => email
            [value] => 
            [extra] => Array
                (
                    [title_display] => inline
                    [private] => 0
                    [disabled] => 0
                    [unique] => 0
                    [width] => 
                    [description] => 
                    [attributes] => Array
                        (
                        )

                    [conditional_component] => 
                    [conditional_operator] => =
                    [conditional_values] => 
                )

            [mandatory] => 1
            [weight] => 4
            [page_num] => 1
        )

    [#webform_private] => 0
    [#validated] => 1
    [#webform_validated] => 
)
7
  • "doesn't work"? Like, nothing happens? Or there is an error message? And could you maybe dpr() or var_dump() it so we could readily see what Webform is doing with email fields?
    – Mołot
    Commented Aug 21, 2013 at 11:20
  • Yeah nothing happens. When you add autocomplete to a regular text field, a little image appears on the right, which turns blue when it's sending / receiving queries. Applying the same rule to e-mail field doesn't show this. It's just a regular textfield that doesn't do anything. I'll get dpr(); added to the original post now. Commented Aug 21, 2013 at 11:26
  • Probably because webform adds it's own #ajax or makes this fieldset or other structure. That's why I asked for a dump.
    – Mołot
    Commented Aug 21, 2013 at 11:28
  • What's the best way of getting the full dpr output on here. It's rather large! Commented Aug 21, 2013 at 11:28
  • @BeardedGeek Please don't add the full output from a dpr()...find the bits that are relevant to your question, and extract those
    – Clive
    Commented Aug 21, 2013 at 11:33

2 Answers 2

2

You can only use type of fields which are defined in hook_element_info.

List all the type of elements using drush by:

drush ev "print_r(array_keys(module_invoke_all('element_info')));"

If you don't need to use Webform email, check the Email field module how it's implementing such element type. See: Usage of email field with the form API.

0

As far as I can see, Webform module provides it's own form elements for email and some other kinds of data, and it simply does not implement autocomplete for them. You need to either implement hook_webform_component_info in your custom module to add this functionality, or fill a feature request on webform's issue queue.

1
  • I'm not sure on how I would use that hook to do it, so I've submitted a feature request within webform's issue queue - drupal.org/node/2070825 Commented Aug 21, 2013 at 13:15

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.