Commit 6730c11e authored by jaapjansma's avatar jaapjansma
Browse files

fixed issue with custom fields on expense lines

parent 9033c3d2
......@@ -52,12 +52,14 @@ class CRM_Expenses_Form_Expense extends CRM_Core_Form {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/expense/form', ['id' => $this->getEntityId(), 'action' => 'update']));
}
if (!empty($_POST['hidden_custom'])) {
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Expense', $this->getEntityId());
$type_id = $this->getSubmitValue('type_id');
CRM_Custom_Form_CustomData::preProcess($this, NULL, $type_id, 1, 'Expense', $this->getEntityId());
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
if (!$this->getEntityId() && !empty($_POST['hidden_custom'])) {
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'ExpenseLine', NULL);
$type_id = $this->getSubmitValue('type_id');
CRM_Custom_Form_CustomData::preProcess($this, NULL, $type_id, 1, 'ExpenseLine', NULL);
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
......
......@@ -15,6 +15,8 @@ class CRM_Expenses_Form_ExpenseLine extends CRM_Core_Form {
protected $_expenseLine;
protected $_expense;
public function getDefaultEntity() {
return 'ExpenseLine';
}
......@@ -56,7 +58,7 @@ class CRM_Expenses_Form_ExpenseLine extends CRM_Core_Form {
$this->assign('expense', $this->_expense);
if (!empty($_POST['hidden_custom'])) {
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'ExpenseLine', $this->getEntityId());
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_expense['type_id'], 1, 'ExpenseLine', $this->getEntityId());
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
......@@ -72,7 +74,7 @@ class CRM_Expenses_Form_ExpenseLine extends CRM_Core_Form {
$this->addMoney('amount', E::ts('Amount'), TRUE, NULL, FALSE);
$this->addButtons([
['type' => 'submit', 'name' => E::ts('Submit'), 'isDefault' => TRUE],
['type' => 'upload', 'name' => E::ts('Submit'), 'isDefault' => TRUE],
['type' => 'cancel', 'name' => E::ts('Cancel')]
]);
} else {
......
......@@ -13,8 +13,8 @@
<url desc="Documentation">https://lab.civicrm.org/extensions/expenses/blob/master/README.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-10-20</releaseDate>
<version>1.0.7</version>
<releaseDate>2020-11-10</releaseDate>
<version>1.0.8</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.0</ver>
......
......@@ -23,8 +23,7 @@
<div class="content">{$form.amount.html|crmAddClass:eight}&nbsp;<span>{$expense.currency}</span></div>
<div class="clear"></div>
</div>
{include file="CRM/Expenses/common/customDataBlock.tpl" customDataType='ExpenseLine' entityID=$expenseLine.id}
{include file="CRM/Expenses/common/customDataBlock.tpl" customDataType='ExpenseLine' entityID=$expenseLine.id expense_type_id=$expense.type_id}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
......
......@@ -7,11 +7,15 @@
<script type="text/javascript">
CRM.$(function($) {
function updateCustomData{/literal}{$customDataType}{literal}() {
var subType = $('#type_id').val();
CRM.buildCustomData('{/literal}{$customDataType}{literal}', subType, false, false, false, false, false, {/literal}{$cid}{literal});
var subType = '{/literal}{$expense_type_id}{literal}';
if ($('#type_id').length) {
subType = $('#type_id').val();
}
CRM.buildCustomData('{/literal}{$customDataType}{literal}', subType, false, false, false, false, false, {/literal}{$cid}{literal});
}
if ($('#type_id').length) {
$('#type_id').on('change', updateCustomData{/literal}{$customDataType}{literal});
}
$('#type_id').on('change', updateCustomData{/literal}{$customDataType}{literal});
updateCustomData{/literal}{$customDataType}{literal}();
});
</script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment