@@ -364,7 +364,9 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
364
364
return _coerce ( containerIn , containerOut , attributes , attribute , dflt ) . val ;
365
365
} ;
366
366
367
- function _coerce ( containerIn , containerOut , attributes , attribute , dflt ) {
367
+ function _coerce ( containerIn , containerOut , attributes , attribute , dflt , opts ) {
368
+ var shouldValidate = ( opts || { } ) . shouldValidate ;
369
+
368
370
var attr = nestedProperty ( attributes , attribute ) . get ( ) ;
369
371
if ( dflt === undefined ) dflt = attr . dflt ;
370
372
var src = '' ; // i.e. default
@@ -376,7 +378,7 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
376
378
var template = containerOut . _template ;
377
379
if ( valIn === undefined && template ) {
378
380
valIn = nestedProperty ( template , attribute ) . get ( ) ;
379
- if ( valIn !== undefined ) src = 't' ; // template
381
+ if ( valIn !== undefined && shouldValidate && validate ( valIn , attr ) ) src = 't' ; // template
380
382
381
383
// already used the template value, so short-circuit the second check
382
384
template = 0 ;
@@ -401,7 +403,7 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
401
403
coerceFunction ( valIn , propOut , dflt , attr ) ;
402
404
403
405
var valOut = propOut . get ( ) ;
404
- if ( valOut !== undefined ) src = 'c' ; // container
406
+ if ( valOut !== undefined && shouldValidate && validate ( valIn , attr ) ) src = 'c' ; // container
405
407
406
408
// in case v was provided but invalid, try the template again so it still
407
409
// overrides the regular default
@@ -410,7 +412,7 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
410
412
coerceFunction ( valIn , propOut , dflt , attr ) ;
411
413
valOut = propOut . get ( ) ;
412
414
413
- if ( valOut !== undefined ) src = 't' ; // template
415
+ if ( valOut !== undefined && shouldValidate && validate ( valIn , attr ) ) src = 't' ; // template
414
416
}
415
417
416
418
return {
@@ -422,13 +424,17 @@ function _coerce(containerIn, containerOut, attributes, attribute, dflt) {
422
424
423
425
/**
424
426
* Variation on coerce
427
+ * useful when setting an attribute to a valid value
428
+ * can change the default for another attribute.
425
429
*
426
430
* Uses coerce to get attribute value if user input is valid,
427
431
* returns attribute default if user input it not valid or
428
432
* returns false if there is no user input.
429
433
*/
430
434
exports . 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
+ } ) ;
432
438
return ( out . src && out . inp !== undefined ) ? out . val : false ;
433
439
} ;
434
440
0 commit comments