0

i have a select option value , in change create a text field with auto complete feature, every thing is ok , but autocomplelete of this element not work!!!

part of my code

        $form['azlocation']=array(
            '#type' => 'select',
            '#title' => 'location',
            '#options' => array(1,2,3),
            '#default_value' => 1,
            '#description' => t('select your news location.'),
            '#ajax' => array(
                    'event' => 'change',
                    'callback' => 'country_select_f',
                    //'path' =>'roadtonowhere',
                    'wrapper' => 'city-term',
                    'method' => 'replace',
                    'effect' => 'fade',
            ),
            );
    $form['field_terms_city']= array(
            '#markup' => '<div id="city-term"></div>');



    function country_select_f(&$form, $form_state){
$form['city_list_item2'] =array(
        '#type' => 'textfield',
        '#title' => t('select city (optional)'),
        '#autocomplete_path' => 'user/autocomplete',
        '#weight' => -1,
        '#attributes' => array('id' =>'city-term-select'),
);

where is the problem?

1
  • tnx. for your reply. but before i test this i myself found solution. tnx – Yuseferi Jun 11 '12 at 7:41
0

Try this.

$form['azlocation'] = array( 
'#type' => 'select',
'#title' => 'location',
'#options' => array(1, 2, 3),
'#default_value' => 1,
'#description' => t('select your news location.'),
'#ajax' => array(
  'event' => 'change',
  'callback' => 'country_select_f',
  //'path' =>'roadtonowhere',
  'wrapper' => 'city-term',
  'method' => 'replace',
  'effect' => 'fade',
 ),
 );
 $form['field_terms_city'] = array(
 '#type' => 'textfield',
 '#title' => t('select city (optional)'),
 '#prefix' => '<div id="city-term">',
 '#suffix' => '</div>',
 );
 return $form;
}
function country_select_f($form, $form_state){
   $form['field_terms_city']['#autocomplete_path'] = 'user/autocomplete';
   return $form['field_terms_city'];
}
0

I've done it by this:

$form['azlocation']=array(
            '#type' => 'select',
            '#title' => 'location',
            '#options' => $tags,
            '#default_value' => 1,
            '#description' => t('select your news location.'),
            '#ajax' => array(
                    'event' => 'change',
                    'callback' => 'country_select_f',
                    //'path' =>'roadtonowhere',
                    'wrapper' => 'city-term',
                    'method' => 'replace',
                    'effect' => 'fade',
            ),
            );

    $form['field_terms_city']= array(
            '#markup' => '<div id="city-term"></div>');

function country_select_f(&$form, $form_state){

$form['city_list_item'] =array(
        '#type' => 'textfield',
        '#title' => t('select city (optional)'),
        //'#autocomplete_path' => 'user/autocomplete',
        '#autocomplete_path' => "events/autocomplete/".$form_state['triggering_element']['#value'],
        //'#autocomplete_path' => "events/autocomplete/".$form_state['triggering_element']['#value'],
        '#weight' => -1,
        '#attributes' => array('id' =>'city-term-select'),
);
return ('<div id="city-term">'.drupal_render($form['city_list_item']).'</div>');
}

My trick was to use:

return ('<div id="city-term">'.drupal_render($form['city_list_item']).'</div>');

I hope this be useful in the future for users with similar problem.

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.