在创建发票时,我希望能够根据所选客户本国货币设置下拉货币列表的默认值,但我仍希望能够通过选择其他货币来更改此默认值。
例如,我的货币表包含所有可用货币
例如,当选择此客户时,我希望货币更改为澳元,但我仍希望能够更改它。
不太确定从哪里开始我可以提供任何线索,非常感谢。
这是我的观看文件add.ctp
的代码<div class="invoices form large-9 medium-8 columns content">
<?= $this->Form->create($invoice) ?>
<fieldset>
<legend><?= __('Add Invoice') ?></legend>
<?php
echo $this->Form->input('customer_id', ['options' => $customers, 'empty' => true,'id'=>'customers']);
echo $this->Form->input('currency_id', ['options' => $currencies, 'default'=> 1]);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
这是我在InvoiceController中的添加功能。
public function add()
{
$invoice = $this->Invoices->newEntity();
if ($this->request->is('post')) {
$invoice = $this->Invoices->patchEntity($invoice, $this->request->data);
if ($this->Invoices->save($invoice)) {
$this->Flash->success(__('The invoice has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The invoice could not be saved. Please, try again.'));
}
$customers = $this->Invoices->Customers->find('list', ['limit' => 200]);
$currencies = $this->Invoices->Currencies->find('list', ['limit' => 200]);
$this->set(compact('invoice', 'customers', 'users', 'customerContacts', 'aircraftRegistrations', 'shippingCompanies', 'supervisingEngineerUsers', 'jobTypes', 'openedByUsers', 'assignedToUsers', 'currencies'));
$this->set('_serialize', ['invoice']);
}