Drupal-7
Le deuxième autocomplétion de taxonomie dépend du premier autocomplet de taxinomie.
Ajouter offre:
étape 1) Pays avec autocomplet, Ville est vide
Pays: U
------------ USA
Ville:
étape 2) lorsque nous choisissons USA nous pouvons utiliser la ville avec autocomplet
Pays: États-Unis
Ville: Soyez
------- Berkeley
Étape 3), mais nous insérons tout nouvel élément Bexxx
Pays: États-Unis
Ville: Bexxx
offre de recherche:
Étape 1) Pays - sélectionnez États-Unis dans la liste, la ville est vide
Pays: USA
----------- Allemagne
Ville:
Étape 2) lorsque nous choisissons USA nous avons 3 articles sur la liste
Pays: États-Unis
Ville: Berkeley
------- ------- Berlin
BexxxxxLa seconde autocomplétion de taxonomie dépend de la première autocomplétion de taxonomie
0
A
Répondre
1
J'utilise Drupal 6, le module Hierarchical select et Views. Puis dans les vues j'ai utilisé le champ avec le filtre exposé.
0
Ceci est un exemple simple de champs dépendants. Créez un module simple nommé "myajx" et placez ce code tel quel. Maintenant, accédez par url à savoir "http://localhost/mypage". Maintenant, sélectionnez une valeur dans le premier champ et vous verrez que seules ses valeurs dépendantes sont listées dans le champ ci-dessous.
<?php
/**
* Implementation of hook_menu().
* Registers a form-based page that you can access at "http://localhost/mypage"
*/
function myajx_menu(){
return array(
'mypage' => array(
'title' => 'A page to test ajax',
'page callback' => 'drupal_get_form',
'page arguments' => array('myajx_page'),
'access arguments' => array('access content'),
)
);
}
/**
* A form with a dropdown whose options are dependent on a
* choice made in a previous dropdown.
*
* On changing the first dropdown, the options in the second are updated.
*/
function myajx_page($form, &$form_state) {
// Get the list of options to populate the first dropdown.
$options_first = myajx_first_dropdown_options();
$value_dropdown_first = isset($form_state['values']['dropdown_first']) ? $form_state['values']['dropdown_first'] : key($options_first);
$form['dropdown_first'] = array(
'#type' => 'select',
'#title' => 'First Dropdown',
'#options' => $options_first,
'#default_value' => $value_dropdown_first,
// Bind an ajax callback to the change event (which is the default for the
// select form type) of the first dropdown. It will replace the second
// dropdown when rebuilt
'#ajax' => array(
// When 'event' occurs, Drupal will perform an ajax request in the
// background. Usually the default value is sufficient (eg. change for
// select elements), but valid values include any jQuery event,
// most notably 'mousedown', 'blur', and 'submit'.
'event' => 'change',
'callback' => 'myajx_ajax_callback',
'wrapper' => 'dropdown_second_replace',
),
);
$form['dropdown_second'] = array(
'#type' => 'select',
'#title' => 'Second Dropdown',
'#prefix' => '<div id="dropdown_second_replace">',
'#suffix' => '</div>',
'#options' => myajx_second_dropdown_options($value_dropdown_first),
'#default_value' => isset($form_state['values']['dropdown_second']) ? $form_state['values']['dropdown_second'] : '',
);
return $form;
}
/**
* Selects just the second dropdown to be returned for re-rendering
*
* Since the controlling logic for populating the form is in the form builder
* function, all we do here is select the element and return it to be updated.
*
* @return renderable array (the second dropdown)
*/
function myajx_ajax_callback($form, $form_state) {
return $form['dropdown_second'];
}
/**
* Helper function to populate the first dropdown. This would normally be
* pulling data from the database.
*
* @return array of options
*/
function myajx_first_dropdown_options() {
return array(
'colors' => 'Names of colors',
'cities' => 'Names of cities',
'animals' => 'Names of animals',
);
}
function myajx_second_dropdown_options($key = '') {
$options = array(
'colors' => array(
'red' => 'Red',
'green' => 'Green',
'blue' => 'Blue'
),
'cities' => array(
'paris' => 'Paris, France',
'tokyo' => 'Tokyo, Japan',
'newyork' => 'New York, US'
),
'animals' => array(
'dog' => 'Dog',
'cat' => 'Cat',
'bird' => 'Bird'
),
);
if (isset($options[$key])) {
return $options[$key];
}
else {
return array();
}
}
Questions connexes
- 1. autocomplétion JComboBox
- 2. MySql - autocomplétion
- 3. Suggestion d'étiquette (autocomplétion de variable)
- 4. Eclipse Groovy et autocomplétion
- 5. Jquery Bouclage autocomplétion
- 6. autocomplétion personnalisé pour zsh
- 7. Eclipse: autocomplétion instantané
- 8. SharePoint 2010 jQuery autocomplétion
- 9. autocomplétion dans Xcode
- 10. rails 3.1.1 autocomplétion
- 11. Eclipse PDT (hélios) autocomplétion
- 12. Fancybox vs autocomplétion
- 13. autocomplétion pour Ace Editor
- 14. intelij idea scala "" autocomplétion
- 15. taxonomie drupal
- 16. Obtenir toute la taxonomie de mon Drupal
- 17. jQuery UI autocomplétion - IE6 lockup
- 18. Xcode commentaires autocomplétion (style appledoc)
- 19. loopj jQuery Tokeninput (autocomplétion tokenisée) - obtention de la valeur
- 20. StringConverter avec StandardValuesSupported et autocomplétion
- 21. Découvrez la taxonomie des articles
- 22. Aide sur la taxonomie SQL
- 23. Graphique taxonomie
- 24. Vue de taxonomie par défaut
- 25. liste de taxonomie par auteur
- 26. titres de taxonomie Ajouter des
- 27. Arbres de taxonomie générés automatiquement
- 28. Taxonomie: vue de haut niveau?
- 29. Drupal: comment changer la langue actuelle de la taxonomie
- 30. Modèle de données de taxonomie biologique