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 #isAppliedmaster
parent
ae9f2a7cab
commit
40505c3328
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue