1
0
Fork 0

FieldStyler#isApplied added

Field stylers now determine whether they've been applied to the target field
on their own, which solves the problem of the system getting out of sync.

* src/ui/styler/ErrorFieldStyler.js (isApplied): Added
* src/ui/styler/FieldStyler.js (isApplied): Added
* src/ui/styler/NaFieldStyler.js (isApplied): Added
* test/ui/styler/NaFieldStylerTest.js: Test for #isApplied
master
Mike Gerwitz 2016-04-04 15:25:52 -04:00
parent ae9f2a7cab
commit 40505c3328
4 changed files with 74 additions and 0 deletions

View File

@ -35,6 +35,24 @@ module.exports = Class( 'ErrorFieldStyler' )
},
/**
* Determines whether the field has been styled
*
* Having this predicate on the styler rather than the field ensures
* that, even if the two somehow get out of sync (or styles are applied
* elsewhere), application/revocation will function sanely.
*
* @param {DomField} field field to style
* @param {HTMLElement} element DOM element to style
*
* @return {boolean} whether FIELD has been styled by this styler
*/
'public isApplied': function( field, element )
{
return /\binvalid_field\b/.test( element.className );
},
'public applyStyle': function( field, element, row, msg )
{
var _self = this;

View File

@ -36,6 +36,20 @@ module.exports = AbstractClass( 'FieldStyler',
*/
'abstract public getId': [],
/**
* Determines whether the field has been styled
*
* Having this predicate on the styler rather than the field ensures
* that, even if the two somehow get out of sync (or styles are applied
* elsewhere), application/revocation will function sanely.
*
* @param {DomField} field field to style
* @param {HTMLElement} element DOM element to style
*
* @return {boolean} whether FIELD has been styled by this styler
*/
'abstract public isApplied': [ 'field', 'element' ],
/**
* Apply style to field
*

View File

@ -43,6 +43,24 @@ module.exports = Class( 'NaFieldStyler' )
},
/**
* Determines whether the field has been styled
*
* Having this predicate on the styler rather than the field ensures
* that, even if the two somehow get out of sync (or styles are applied
* elsewhere), application/revocation will function sanely.
*
* @param {DomField} field field to style
* @param {HTMLElement} element DOM element to style
*
* @return {boolean} whether FIELD has been styled by this styler
*/
'public isApplied': function( field, element )
{
return /\bhidden\b/.test( element.className );
},
/**
* Apply style to field
*

View File

@ -221,6 +221,30 @@ describe( 'ui.styler.NaFieldStyler', function()
} );
describe( '#isApplied', function()
{
it( 'recognizes when applied', function()
{
var element = {
className: '',
};
var sut = Sut(),
field = getStubField( element );
sut.applyStyle( field, element, [] );
expect( sut.isApplied( field, element ) )
.to.be.true;
sut.revokeStyle( field, element, [] );
expect( sut.isApplied( field, element ) )
.to.be.false;
} );
} );
describe( 'protected API', function()
{
describe( '#isSubField', function()