@@ -364,7 +364,9 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
364364 return _coerce ( containerIn , containerOut , attributes , attribute , dflt ) . val ;
365365} ;
366366
367- function _coerce ( containerIn , containerOut , attributes , attribute , dflt ) {
367+ function _coerce ( containerIn , containerOut , attributes , attribute , dflt , opts ) {
368+ var shouldValidate = ( opts || { } ) . shouldValidate ;
369+
368370 var attr = nestedProperty ( attributes , attribute ) . get ( ) ;
369371 if ( dflt === undefined ) dflt = attr . dflt ;
370372 var src = '' ; // i.e. default
@@ -376,7 +378,7 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
376378 var template = containerOut . _template ;
377379 if ( valIn === undefined && template ) {
378380 valIn = nestedProperty ( template , attribute ) . get ( ) ;
379- if ( valIn !== undefined ) src = 't' ; // template
381+ if ( valIn !== undefined && shouldValidate && validate ( valIn , attr ) ) src = 't' ; // template
380382
381383 // already used the template value, so short-circuit the second check
382384 template = 0 ;
@@ -401,7 +403,7 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
401403 coerceFunction ( valIn , propOut , dflt , attr ) ;
402404
403405 var valOut = propOut . get ( ) ;
404- if ( valOut !== undefined ) src = 'c' ; // container
406+ if ( valOut !== undefined && shouldValidate && validate ( valIn , attr ) ) src = 'c' ; // container
405407
406408 // in case v was provided but invalid, try the template again so it still
407409 // overrides the regular default
@@ -410,7 +412,7 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
410412 coerceFunction ( valIn , propOut , dflt , attr ) ;
411413 valOut = propOut . get ( ) ;
412414
413- if ( valOut !== undefined ) src = 't' ; // template
415+ if ( valOut !== undefined && shouldValidate && validate ( valIn , attr ) ) src = 't' ; // template
414416 }
415417
416418 return {
@@ -422,13 +424,17 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
422424
423425/**
424426 * Variation on coerce
427+ * useful when setting an attribute to a valid value
428+ * can change the default for another attribute.
425429 *
426430 * Uses coerce to get attribute value if user input is valid,
427431 * returns attribute default if user input it not valid or
428432 * returns false if there is no user input.
429433 */
430434exports . coerce2 = function ( containerIn , containerOut , attributes , attribute , dflt ) {
431- var out = _coerce ( containerIn , containerOut , attributes , attribute , dflt ) ;
435+ var out = _coerce ( containerIn , containerOut , attributes , attribute , dflt , {
436+ shouldValidate : true
437+ } ) ;
432438 return ( out . src && out . inp !== undefined ) ? out . val : false ;
433439} ;
434440
0 commit comments