Permalink
Browse files

Textinput: Remove "ui-input-has-clear" class from wrapper, not element

Also fixes line length issues introduced by previous commit, and adds a test to
make sure clearBtn-related markup is correctly added/removed.
  • Loading branch information...
gabrielschulhof committed Feb 7, 2014
1 parent e3761c2 commit 469665140b07b8360d5e983a0bd9c8ca93fe3ee6
Showing with 31 additions and 3 deletions.
  1. +5 −3 js/widgets/forms/clearButton.js
  2. +2 −0 tests/unit/textinput/index.html
  3. +24 −0 tests/unit/textinput/textinput_core.js
@@ -91,7 +91,8 @@ define( [
_setOptions: function( options ) {
this._super( options );
if ( options.clearBtn !== undefined && !this.element.is( "textarea, :jqmData(type='range')" ) ) {
if ( options.clearBtn !== undefined &&
!this.element.is( "textarea, :jqmData(type='range')" ) ) {
if ( options.clearBtn ) {
this._addClearBtn();
} else {
@@ -100,7 +101,8 @@ define( [
}
if ( options.clearBtnText !== undefined && this._clearBtn !== undefined ) {
this._clearBtn.text( options.clearBtnText ).attr("title", options.clearBtnText);
this._clearBtn.text( options.clearBtnText )
.attr("title", options.clearBtnText);
}
},
@@ -113,7 +115,7 @@ define( [
},
_destroyClear: function() {
this.element.removeClass( "ui-input-has-clear" );
this.widget().removeClass( "ui-input-has-clear" );
this._unbindClear();
this._clearBtn.remove();
},
@@ -62,6 +62,8 @@
<textarea data-clear-btn="true" id="textarea-clear-btn"></textarea>
<input id="test-clear-btn-option"></input>
<input type="text" id="focus-class-test-for-input"></input>
<textarea id="focus-class-test-for-textarea"></textarea>
</div>
@@ -125,4 +125,28 @@
ok( !d, "native clear button is still visible" );
});
test( "clearBtn option works at runtime", function() {
var input = $( "#test-clear-btn-option" );
deepEqual( input.siblings( "a" ).length, 0,
"input initially has no clear button" );
deepEqual( input.parent().hasClass( "ui-input-has-clear" ), false,
"wrapper does not initially have class 'ui-input-has-clear'" );
input.textinput( "option", "clearBtn", true );
deepEqual( input.siblings( "a" ).length, 1,
"turning on clearBtn option causes an anchor to be added" );
deepEqual( input.parent().hasClass( "ui-input-has-clear" ), true,
"turning on clearBtn option causes 'ui-input-has-clear' to be " +
"added to wrapper" );
input.textinput( "option", "clearBtn", false );
deepEqual( input.siblings( "a" ).length, 0,
"turning off clearBtn removes clear button anchor" );
deepEqual( input.parent().hasClass( "ui-input-has-clear" ), false,
"turning off clearBtn removes wrapper class 'ui-input-has-clear'" );
});
})(jQuery);

0 comments on commit 4696651

Please sign in to comment.