Bladeren bron

datefield 格式转换: 20120212 -> 2012-02-12

luoyifan 3 jaren geleden
bovenliggende
commit
313c3c030d
1 gewijzigde bestanden met toevoegingen van 14 en 2 verwijderingen
  1. 14 2
      src/controls/input/datefield.js

+ 14 - 2
src/controls/input/datefield.js

@@ -16,7 +16,7 @@ import {PropertyDescription} from "../../PropertyDescription";
 export default function () {
 
     const cc = Ext.form.field.Date.prototype.constructor
-    const {initComponent, getValue} = Ext.form.field.Date.prototype
+    const {initComponent, getValue, valueToRaw} = Ext.form.field.Date.prototype
     Ext.form.field.Date.override({
         constructor(config) {
             const newConfig = _.defaultsDeep({
@@ -36,7 +36,6 @@ export default function () {
             return nv
         },
 
-
         initComponent() {
             const that = this
             const toggle = function (e) {
@@ -66,6 +65,19 @@ export default function () {
                 destory() {
                     $(this.el.dom).off('click', toggle.bind(this))
                 },
+                change: {
+                    fn(sender) {
+                        const value = sender.getRawValue()
+                        if (/^\d{8}$/.test(value)) {
+                            const newValue = [
+                                value.substr(0, 4),
+                                value.substr(4, 2),
+                                value.substr(6, 2)
+                            ].join('-')
+                            sender.setValue(newValue)
+                        }
+                    },
+                }
                 // focus: {
                 //     // 获得焦点后自动下拉
                 //     fn(sender) {