我有一個包含服務列表的下拉字段的表單。這些服務基於已輸入到管理模型「服務」中的內容顯示在drodpown中。SilverStripe - 基於表單字段選擇從管理模型中檢索選中的值
下拉:
<select id="ServiceReq">
<option value="">Service Requested*</option>
<% if getServiceList %>
<% loop getServiceList %>
<option value="$Name">$Name</option>
<% end_loop %>
<% end_if %>
</select>
的服務管理模型的代碼:
<?php
class Service extends DataObject {
private static $db = array(
'Name' => 'varchar',
);
private static $belongs_many_many = array(
'Locations' => 'Location'
);
public static $summary_fields = array(
'Name' => 'Title',
);
private static $field_labels = array(
'Name'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
if ($this->ID) {
$fields->addFieldToTab('Root.Locations', CheckboxSetField::create(
'Locations',
'Locations',
Location::get()->filter(array(
'AcceptingAppointments' => '1'
))->map()
));
}
return $fields;
}
}
我想要做的是,當服務從ServiceReq下拉列表中選擇,我想要檢索位於服務管理模型的位置選項卡中的複選框字段集中的所有選定位置。那麼這些位置將被用來填充位置的形式下拉列表:
<select id="Location">
<option value="">Location/Hospital</option>
</select>
我知道我需要使用當前選擇的服務的ID,但我不知道我怎麼能功能的設置要做到這一點,但是我失去了如何在服務器端設置傳遞給表單的功能。
我怎麼能扎到窗體的功能這一點,雖然,這樣,當我拿起從服務下拉列表中的服務,那麼位置下拉相應地填充? –
SilverStripe中還有一些表單字段模塊,它們使用閉包獲取基於另一個字段的值。這些也可能是一個很好的參考。依賴字段的另一個很好的例子是[依賴下拉模塊](https://github.com/sheadawson/silverstripe-dependentdropdownfield) – muskie9
有很多服務... 25是確切的。在這種情況下,我不確定依賴下拉模塊的設置是否可行。每個服務可以有自己的一組位置,並且如果服務列表增長,那麼看起來依賴下拉模塊功能可能需要更多的代碼行。我覺得它可能會變得多餘。 –