mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Expand forms and improve validation for multi-account piggy banks
This commit is contained in:
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\Form;
|
||||
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@@ -141,12 +142,25 @@ class AccountForm
|
||||
*/
|
||||
public function assetAccountList(string $name, $value = null, ?array $options = null): string
|
||||
{
|
||||
$types = [AccountType::ASSET, AccountType::DEFAULT];
|
||||
$types = [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value];
|
||||
$grouped = $this->getAccountsGrouped($types);
|
||||
|
||||
return $this->select($name, $grouped, $value, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic list of asset accounts.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function assetLiabilityMultiAccountList(string $name, $value = null, ?array $options = null): string
|
||||
{
|
||||
$types = [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value,AccountTypeEnum::LOAN->value];
|
||||
$grouped = $this->getAccountsGrouped($types);
|
||||
|
||||
return $this->multiSelect($name, $grouped, $value, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same list but all liabilities as well.
|
||||
*
|
||||
@@ -154,7 +168,7 @@ class AccountForm
|
||||
*/
|
||||
public function longAccountList(string $name, $value = null, ?array $options = null): string
|
||||
{
|
||||
$types = [AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||
$types = [AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN];
|
||||
$grouped = $this->getAccountsGrouped($types);
|
||||
|
||||
return $this->select($name, $grouped, $value, $options);
|
||||
|
@@ -56,6 +56,25 @@ trait FormSupport
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function multiSelect(string $name, ?array $list = null, $selected = null, ?array $options = null): string
|
||||
{
|
||||
$list ??= [];
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$selected = $this->fillFieldValue($name, $selected);
|
||||
unset($options['autocomplete'], $options['placeholder']);
|
||||
|
||||
try {
|
||||
$html = view('form.multi-select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Could not render multi-select(): %s', $e->getMessage()));
|
||||
$html = 'Could not render multi-select.';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function label(string $name, ?array $options = null): string
|
||||
{
|
||||
$options ??= [];
|
||||
|
Reference in New Issue
Block a user