0

I'm doing something wrong when configuring the autocomplete field in my content type.

Trying to use it results in a popup with the following message:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: http://volley3.localhost:8082/autocomplete_widgets/field_collection_item/spelersfiche_vraagantwoord/spelersfiche_va_vraag
StatusText: OK
ResponseText: <?php{"Naam":"\u003Cdiv class=\u0022reference-autocomplete\u0022\u003ENaam\u003C\u002Fdiv\u003E"}

When i look with firebug, the request being made is actualy:

http://volley3.localhost:8082/autocomplete_widgets/field_collection_item/spelersfiche_vraagantwoord/spelersfiche_va_vraag/n

(with 'n' being the contents of the autocomplete box)

This returns the same response as the popup mentions.

The code from the module which i used to create the content type is as follows:

<?php
function spelersfiche_install() {
    $t = get_t();

    $spelersfiche = array(
        'type' => 'spelersfiche',
        'name' => $t('Spelersfiche'),
        'base' => 'node_content',
        'description' => $t('spelersfiche'),
        'title_label' => $t('title'),
        'custom' => TRUE
    );

    $content_type = node_type_set_defaults($spelersfiche);

    node_type_save($content_type);

    foreach (_spelersfiche_installed_fields() as $field) {
        field_create_field($field);
    }

    foreach (_spelersfiche_installed_instances() as $instance) {
        field_create_instance($instance);
    }

    node_types_rebuild();
    menu_rebuild();
}

function spelersfiche_uninstall() {
    // http://api.drupal.org/api/function/db_query/7
    $sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
    $result = db_query($sql, array(':type' => 'spelersfiche'));
    $nids = array();
    foreach ($result as $row) {
        $nids[] = $row->nid;
    }

    // http://api.drupal.org/api/function/node_delete_multiple/7
    node_delete_multiple($nids);

    // http://api.drupal.org/api/function/field_delete_field/7
    foreach (array_keys(_spelersfiche_installed_fields()) as $field) {
        field_delete_field($field);
    }

    // http://api.drupal.org/api/function/field_delete_field/7
    $instances = field_info_instances('node', '_spelersfiche');
    foreach ($instances as $instance_name => $instance) {
        field_delete_instance($instance);
    }

    // http://api.drupal.org/api/function/node_type_delete/7
    node_type_delete('spelersfiche');

    // http://api.drupal.org/api/function/field_purge_batch/7
    field_purge_batch(1000);
}

function _spelersfiche_installed_fields() {
    $t = get_t();

    return array(
        'spelersfiche_va_vraag' => array(
            'field_name' => 'spelersfiche_va_vraag',
            'cardinality' => '1',
            'type' => 'text',
            'module' => 'text',
            'settings' => array(
                'max_length' => '255',
            )
        ),
        'spelersfiche_va_antwoord' => array(
            'field_name' => 'spelersfiche_va_antwoord',
            'cardinality' => '1',
            'type' => 'text',
            'settings' => array(
                'max_length' => '255',
            )
        ),
        'spelersfiche_vraagantwoord' => array(
            'field_name' => 'spelersfiche_vraagantwoord',
            'cardinality' => '-1',
            'type' => 'field_collection',
        )
    );
}

function _spelersfiche_installed_instances() {
    $t = get_t();

    return array(
        'spelersfiche_va_vraag' => array(
            'field_name' => 'spelersfiche_va_vraag',
            'label' => $t('vraag'),
            'entity_type' => 'field_collection_item',
            'bundle' => 'spelersfiche_vraagantwoord',
            'settings' => array(
                'text_processing' => '0',
                'user_register_form' => FALSE,
            ),
            'widget' => array(
                'settings' => array(
                    'autocomplete_case' => '1',
                    'autocomplete_match' => 'contains',
                    'size' => '60',
                ),
                'type' => 'autocomplete_widgets_flddata',
                'weight' => '1',
            ),
            'display' => array(
                'default' => array(
                    'label' => 'hidden',
                    'type' => 'text_default',
                ),
            )
        ),
        'spelersfiche_va_antwoord' => array(
            'field_name' => 'spelersfiche_va_antwoord',
            'label' => $t('antwoord'),
            'entity_type' => 'field_collection_item',
            'bundle' => 'spelersfiche_vraagantwoord',
            'widget' => array(
                'type' => 'text_textfield',
            ),
            'display' => array(
                'default' => array(
                    'label' => 'hidden', 
                    'type' => 'text_default',
                ),
            )
        ),
        'spelersfiche_vraagantwoord' => array(
            'field_name' => 'spelersfiche_vraagantwoord',
            'entity_type' => 'node',
            'bundle' => 'spelersfiche',
            'display' => array(
                'default' => array(
                    'label' => 'above',
                    'module' => 'field_collection',
                    'settings' => array(
                        'add' => 'Add',
                        'delete' => 'Delete',
                        'description' => TRUE,
                        'edit' => 'Edit',
                        'view_mode' => 'full',
                    ),
                    'type' => 'field_collection_view',
                    'weight' => 1,
                ),
                'teaser' => array(
                    'label' => 'above',
                    'settings' => array(),
                    'type' => 'hidden',
                    'weight' => 0,
                ),
            ),
            'widget' => array(
                'type' => 'field_collection_embed',
            )
        )
    );
}

So basicaly it's a content type which has a field-collection field. The field collection contains 2 textfields of which i want the first one to be an autocomplete for the existing values but with possibility to add new items.

Serving as a question - answer input where the questions are reusable.

My guess would be that the <?php at the front of the response is making the response an invalid json object,

dependent modules used:

  • Autocomplete Widgets
  • Field collection

Any help is welcome.

1
  • I discovered what the problem was. I had carriage return + new line at the end of my lines instead of just new lines. apparantly this causes the interface to have problems correctly closing and opening php code tags. Because of this the answer from the other modules' ajax-call wasn't a valid json format anymore. Commented Apr 30, 2012 at 18:39

1 Answer 1

2

I discovered what the problem was.

I had carriage return and new line at the end of my lines instead of just a new line. Apparantly this causes the interface to have problems correctly closing and opening php code tags.

Because of this the answer from the other modules' ajax-call wasn't a valid json format anymore.

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.