Drupal-7
第2タクソノミーオートコンプリートは、第1タクソノミーオートコンプリートに依存する。
のオファー追加:autocompletで
ステップ1)国、都市、空
国である:U
------------ USA
市:
ステップUSA
市:う
-------バークレー
私たちはアメリカを選択すると、2)その後、我々はautocomplet
国と都市を使用することができます
ステップ3)私たちはちょうど新しい項目を挿入Bexxx
国:USA
市:Bexxx
検索を提供:
ステップ1)国は - リストから米国を選択し、市は
空の国です。 USA
-----------ドイツ
市:
ステップ2)私たちは、米国を選択したときに、我々は、リスト上の3つのアイテムを持っています
国:USA
市:バークレー
-------ベルリン
------- Bexxxxx第2タクソノミーオートコンプリートは、第1タクソノミーオートコンプリートに依存する
0
A
答えて
1
私はDrupalの6、モジュールHierarchical selectとViewsを使用しています。その後、ビューでは、露出したフィルターでフィールドを使用しました。
0
これは、従属フィールドの簡単な例です。 "myajx"という名前の単純なモジュールを作り、このコードをそのまま置いてください。今すぐURL「http://localhost/mypage」にアクセスしてください。最初のフィールドから値を選択すると、その従属値のみが下のフィールドに表示されます。
<?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();
}
}
関連する問題
- 1. 第1の値に依存する第2の選択タグ
- 2. 第1列と第2列の値に基づく第3列
- 3. 依存関係のテストを追加する:Relationshipモデルの破壊(第11章、演習1 Railsチュートリアル、第2版)
- 4. WPF - 第1ウィンドウから第2ウィンドウを制御します。
- 5. バッシュAWK、第1および第2の出力(int)を取得
- 6. ExtJS 6.第2ストアコンストラクタの第1ストアのデータを使用
- 7. 第1テーブルのIDに基づいて第2テーブルの値を合計する
- 8. 第1列と第2列を比較し、シェルスクリプトの第2列でuniqでない値を取り出す
- 9. 第2列でソートされた第1列によるMySQLの注文
- 10. 第三のレベルが第2レベルの下
- 11. nth-child CSSマッチング第2、第5、第8、...要素
- 12. Windowsアプリケーションの第三者アプリケーションに依存すること
- 13. Iphone:第1セクションのヘッダーを表示させる第2セクションの1番目のセルにスクロールする方法
- 14. 第1 divを左に、第2右を浮動小数点にする方法はありますか?
- 15. kubernetesポッド第2インターフェース
- 16. PGError:ERROR:relation "users"が存在しない - Railsチュートリアル第2版第9章Heroku
- 17. 第1コンボボックス(g:選択)に基づいて第2コンボボックス(g:選択)値を入力する方法は?
- 18. MySQLの第2(または第3)インデックスの文字列
- 19. 休止状態第1レベルキャッシュ
- 20. Drupalイメージは第2のイメージフィールドにリサイズ
- 21. ローカル通知 - ユーザーは「30秒後に任意の第1、第2及びません
- 22. Hibernate第2レベルキャッシュの例
- 23. Infinispan JPA第2レベルキャッシュのデフォルト
- 24. hibernate第2レベルキャッシングのパフォーマンス
- 25. jQuery Datepicker BeforeShowDay第2パラメータ
- 26. Hibernate第2レベルキャッシュとRRトランザクションアイソレーション
- 27. TLNの第1レベルと第2レベルの高さをカスタマイズする方法 - SAP Netweaver 7.3
- 28. Matlab:第1次元の最大和を求め、第2次元でグループ化する
- 29. 第1のデータテーブルに存在するものを取得する方法と、第3のデータテーブルに第2のデータテーブルに存在しないものを取得する方法はありますか?
- 30. 同じホストを指す2つのドメインをトラッキングするにはどうすればいいですか?第2ドメインは第1サイトのサブディレクトリを指します