From d0aee93b6385fc5444219c49cf34ab2927378e55 Mon Sep 17 00:00:00 2001 From: Bayu Hendra Winata Date: Mon, 20 Jan 2020 08:52:50 +0700 Subject: [PATCH] fix: display value for Rupiah --- src/Elements/Rupiah.php | 17 +++++++++++++++++ src/SemanticForm.php | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/Elements/Rupiah.php diff --git a/src/Elements/Rupiah.php b/src/Elements/Rupiah.php new file mode 100644 index 0000000..38defb0 --- /dev/null +++ b/src/Elements/Rupiah.php @@ -0,0 +1,17 @@ +prependLabel('Rp'); + $this->getPrimaryControl()->data('role', 'rupiah'); + } + + public function displayValue() + { + return 'Rp' . number_format($this->getPrimaryControl()->displayValue(), 0, ',', '.'); + } +} diff --git a/src/SemanticForm.php b/src/SemanticForm.php index ff6b831..6d6cc6a 100644 --- a/src/SemanticForm.php +++ b/src/SemanticForm.php @@ -21,6 +21,7 @@ use Laravolt\SemanticForm\Elements\Number; use Laravolt\SemanticForm\Elements\RadioGroup; use Laravolt\SemanticForm\Elements\Redactor; +use Laravolt\SemanticForm\Elements\Rupiah; use Laravolt\SemanticForm\Elements\SelectDateWrapper; use Laravolt\SemanticForm\Elements\SelectDateTimeWrapper; use Laravolt\SemanticForm\Elements\SelectMultiple; @@ -508,8 +509,10 @@ public function rupiah($name, $defaultValue = null) { \Stolz\Assets\Laravel\Facade::group('laravolt')->add('autoNumeric'); - $input = $this->input($name, $defaultValue)->prependLabel('Rp'); - $input->getPrimaryControl()->data('role', 'rupiah'); + $text = $this->text($name, $defaultValue); + // $input = $this->input($name, $defaultValue)->prependLabel('Rp'); + // $input->getPrimaryControl()->data('role', 'rupiah'); + $input = (new Rupiah($text)); return $input; }