From 39853fda45a409e9dc47d7358fbd9b03ad1d33b5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=CC=88rn=20Zaefferer?= Date: Mon, 26 Oct 2015 13:13:42 -0400 Subject: [PATCH] Selectmenu: Handle form resets Fixes #12236 Ref gh-1550 --- tests/unit/selectmenu/core.js | 18 ++++++++++++++++++ tests/unit/selectmenu/selectmenu.html | 4 ++-- ui/widgets/selectmenu.js | 7 +++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tests/unit/selectmenu/core.js b/tests/unit/selectmenu/core.js index 689668e70..1c1a6b622 100644 --- a/tests/unit/selectmenu/core.js +++ b/tests/unit/selectmenu/core.js @@ -329,4 +329,22 @@ $.each( [ } ); } ); + asyncTest( "Selectmenu should reset when its parent form resets", function() { + expect( 2 ); + + var element = $( "#speed" ).selectmenu(), + widget = element.selectmenu( "widget" ), + initialValue = element.val(), + form = element.closest( "form" ); + + element.val( "Slower" ); + element.selectmenu( "refresh" ); + equal( $.trim( widget.text() ), "Slower" ); + form[ 0 ].reset(); + setTimeout( function() { + equal( $.trim( widget.text() ), initialValue ); + start(); + } ); + } ); + } ); diff --git a/tests/unit/selectmenu/selectmenu.html b/tests/unit/selectmenu/selectmenu.html index 1df6e3ebc..be8b826c8 100644 --- a/tests/unit/selectmenu/selectmenu.html +++ b/tests/unit/selectmenu/selectmenu.html @@ -13,7 +13,7 @@
-
+
-
+ ", options: { @@ -76,6 +77,7 @@ return $.widget( "ui.selectmenu", { this._drawButton(); this._drawMenu(); + this._bindFormResetHandler(); this._rendered = false; this.menuItems = $(); @@ -675,12 +677,13 @@ return $.widget( "ui.selectmenu", { }, _destroy: function() { + this._unbindFormResetHandler(); this.menuWrap.remove(); this.button.remove(); this.element.show(); this.element.removeUniqueId(); this.labels.attr( "for", this.ids.element ); } -} ); +} ] ); } ) ); -- 2.39.5