Browse Source

修复单位符号为不填时,存入数据库的值为''的问题

famio 4 years ago
parent
commit
025abdfd36
1 changed files with 17 additions and 14 deletions
  1. 17 14
      src/Form/Field/Currency.php

+ 17 - 14
src/Form/Field/Currency.php

@@ -18,11 +18,11 @@ class Currency extends Text
      * @var array
      */
     protected $options = [
-        'alias'              => 'currency',
-        'radixPoint'         => '.',
-        'prefix'             => '',
+        'alias' => 'currency',
+        'radixPoint' => '.',
+        'prefix' => '',
         'removeMaskOnSubmit' => true,
-        'rightAlign'         => false,
+        'rightAlign' => false,
     ];
 
     /**
@@ -51,16 +51,6 @@ class Currency extends Text
         return $this->mergeOptions(compact('digits'));
     }
 
-    /**
-     * @param mixed $value
-     *
-     * @return mixed
-     */
-    protected function prepareInputValue($value)
-    {
-        return str_replace(',', '', $value);
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -73,4 +63,17 @@ class Currency extends Text
 
         return parent::render();
     }
+
+    /**
+     * @param mixed $value
+     *
+     * @return mixed
+     */
+    protected function prepareInputValue($value)
+    {
+        if (empty($value)) {
+            $value = 0;
+        }
+        return str_replace(',', '', $value);
+    }
 }