Ver Fonte

修复浏览器回退时switcher插件显示异常问题

jqh há 5 anos atrás
pai
commit
065d1a2866

+ 12 - 1
src/Form/Field/SwitchField.php

@@ -108,7 +108,18 @@ class SwitchField extends Field
         $this->attribute('data-plugin', $this->getFormElementId().'switchery');
 
         $this->script = <<<JS
-function swty(){\$('[data-plugin="{$this->getFormElementId()}switchery"]').each(function(){new Switchery($(this)[0],$(this).data())})} swty();
+(function () {
+    function swty(){
+        var ipt = \$('[data-plugin="{$this->getFormElementId()}switchery"]');
+        
+        ipt.parent().find('.switchery').remove();
+        
+        ipt.each(function() {
+            new Switchery($(this)[0],$(this).data())
+        })
+    } 
+    swty();
+})()
 JS;
 
         return parent::render();

+ 1 - 0
src/Grid/Displayers/SwitchDisplay.php

@@ -89,6 +89,7 @@ EOF;
 (function(){
     var swt = $('.grid-switch-{$this->grid->getName()}'), t;
     function init(){
+        swt.parent().find('.switchery').remove();
         swt.each(function(k){
             t = $(this);
             new Switchery(t[0], t.data())

+ 2 - 0
src/Grid/Displayers/SwitchGroup.php

@@ -54,6 +54,8 @@ class SwitchGroup extends SwitchDisplay
     function init(){
         swt.each(function(){
              t = $(this);
+             t.parent().find('.switchery').remove();
+             
              new Switchery(t[0], t.data())
         })
     }