浏览代码

bind a event for form reset

Aimeast 12 年之前
父节点
当前提交
821338949c
共有 1 个文件被更改,包括 13 次插入0 次删除
  1. 13 0
      static/js/bootstrapSwitch.js

+ 13 - 0
static/js/bootstrapSwitch.js

@@ -18,6 +18,7 @@
               , $switchLeft
               , $switchRight
               , $label
+              , $form = $element.closest('form')
               , myClasses = ""
               , classes = $element.attr('class')
               , color
@@ -201,6 +202,18 @@
                 });
               }
             });
+
+            if ($form.data('bootstrapSwitch') != 'injected') {
+              $form.bind('reset', function () {
+                setTimeout(function () {
+                  $form.find('.switch').each(function () {
+                    var $this = $(this);
+                    $this.bootstrapSwitch('setState', $this.bootstrapSwitch('status'));
+                  });
+                }, 1);
+              });
+              $form.data('bootstrapSwitch', 'injected');
+            }
           }
         );
       },