diff --git a/src/ui/styler/ErrorFieldStyler.js b/src/ui/styler/ErrorFieldStyler.js index a065047..9f44016 100644 --- a/src/ui/styler/ErrorFieldStyler.js +++ b/src/ui/styler/ErrorFieldStyler.js @@ -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; diff --git a/src/ui/styler/FieldStyler.js b/src/ui/styler/FieldStyler.js index 7ed5cfe..3d62cd9 100644 --- a/src/ui/styler/FieldStyler.js +++ b/src/ui/styler/FieldStyler.js @@ -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 * diff --git a/src/ui/styler/NaFieldStyler.js b/src/ui/styler/NaFieldStyler.js index 9889558..1f03d42 100644 --- a/src/ui/styler/NaFieldStyler.js +++ b/src/ui/styler/NaFieldStyler.js @@ -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 * diff --git a/test/ui/styler/NaFieldStylerTest.js b/test/ui/styler/NaFieldStylerTest.js index e1ab337..26c7431 100644 --- a/test/ui/styler/NaFieldStylerTest.js +++ b/test/ui/styler/NaFieldStylerTest.js @@ -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()