Răsfoiți Sursa

#5541 CodeMirror code editor isn't initialized properly sometimes

Aleksandr Trofimov 3 luni în urmă
părinte
comite
ed332041e1
4 a modificat fișierele cu 29 adăugiri și 3 ștergeri
  1. 5 2
      inc/js/classes/BxDolForm.js
  2. 3 0
      inc/js/jquery.webForms.js
  3. 1 1
      package.json
  4. 20 0
      samples/forms.php

+ 5 - 2
inc/js/classes/BxDolForm.js

@@ -38,8 +38,11 @@ function BxDolForm(oOptions)
  */
 BxDolForm.prototype.init = function()
 {
-    if(this._bInitCodeMirror)
-        this.initCodeMirror();
+    if(this._bInitCodeMirror) {
+        setTimeout(() => {
+            this.initCodeMirror();
+        }, 500);
+    }
 };
 
 BxDolForm.prototype.initCodeMirror = function()

+ 3 - 0
inc/js/jquery.webForms.js

@@ -97,6 +97,9 @@
                         eFormSection.removeClass('bx-form-section-hidden');
 
                         $(this).addWebForms();
+                        $(this).find('.CodeMirror').each(function() {
+                            this.CodeMirror.refresh();
+                        });
 
                         //--- fire custom event 'bx_show'
                         eFormSection.trigger('bx_show');

+ 1 - 1
package.json

@@ -11,7 +11,7 @@
     "chart.js": "^4.5.1",
     "chartjs-adapter-moment": "^1.0.1",
     "clipboard": "^2.0.11",
-    "codemirror": "^5.65.19",
+    "codemirror": "^5.65.21",
     "croppie": "^2.6.5",
     "dashjs": "^5.2.0",
     "fancybox": "^3.0.1",

+ 20 - 0
samples/forms.php

@@ -43,6 +43,7 @@ function PageCompMainCode()
             'labels' => array(
                 'type' => 'custom',
                 'name' => 'labels',
+                'caption_src' => 'Labels',
                 'caption' => _t('Labels'),
                 'value' => ['Hello World', 'Привет Мир'],
                 'values' => ['Hello World', 'Привет Мир', 'Guten Tag', 'Жакшы кун'],
@@ -167,6 +168,22 @@ function PageCompMainCode()
                 'required' => true,
             ),
 
+            'color' => array(
+                'type' => 'rgb',
+                'name' => 'color',
+                'caption' => _t('Color'),
+                'value' => 'rgb(16, 164, 164)',
+                'required' => true,
+            ),
+            
+            'code' => array(
+                'type' => 'textarea',
+                'code' => true,
+                'name' => 'code',
+                'caption' => _t('Source code'),
+                'required' => true,                
+            ),            
+
             'header_submit' => array(
                 'type' => 'block_header',
                 'caption' => '',
@@ -206,6 +223,9 @@ function PageCompMainCode()
     $oForm->initChecker();
     if ( $oForm->isSubmittedAndValid() ) {
         echo  MsgBox('Data was successfully submitted');
+        echo '<pre>';
+        print_r($_REQUEST);
+        echo '</pre>';
     }
 
     echo $oForm->getCode();