@@ -343,12 +343,12 @@ exports.valObjectMeta = {
343
343
return false ;
344
344
}
345
345
for ( var j = 0 ; j < v [ i ] . length ; j ++ ) {
346
- if ( ! exports . validate ( v [ i ] [ j ] , arrayItems ? items [ i ] [ j ] : items ) ) {
346
+ if ( ! validate ( v [ i ] [ j ] , arrayItems ? items [ i ] [ j ] : items ) ) {
347
347
return false ;
348
348
}
349
349
}
350
350
}
351
- else if ( ! exports . validate ( v [ i ] , arrayItems ? items [ i ] : items ) ) return false ;
351
+ else if ( ! validate ( v [ i ] , arrayItems ? items [ i ] : items ) ) return false ;
352
352
}
353
353
354
354
return true ;
@@ -369,10 +369,17 @@ exports.valObjectMeta = {
369
369
* as a convenience, returns the value it finally set
370
370
*/
371
371
exports . coerce = function ( containerIn , containerOut , attributes , attribute , dflt ) {
372
- var opts = nestedProperty ( attributes , attribute ) . get ( ) ,
373
- propIn = nestedProperty ( containerIn , attribute ) ,
374
- propOut = nestedProperty ( containerOut , attribute ) ,
375
- v = propIn . get ( ) ;
372
+ var opts = nestedProperty ( attributes , attribute ) . get ( ) ;
373
+ var propIn = nestedProperty ( containerIn , attribute ) ;
374
+ var propOut = nestedProperty ( containerOut , attribute ) ;
375
+ var v = propIn . get ( ) ;
376
+
377
+ var template = containerOut . _template ;
378
+ if ( v === undefined && template ) {
379
+ v = nestedProperty ( template , attribute ) . get ( ) ;
380
+ // already used the template value, so short-circuit the second check
381
+ template = 0 ;
382
+ }
376
383
377
384
if ( dflt === undefined ) dflt = opts . dflt ;
378
385
@@ -387,9 +394,18 @@ exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt
387
394
return v ;
388
395
}
389
396
390
- exports . valObjectMeta [ opts . valType ] . coerceFunction ( v , propOut , dflt , opts ) ;
397
+ var coerceFunction = exports . valObjectMeta [ opts . valType ] . coerceFunction ;
398
+ coerceFunction ( v , propOut , dflt , opts ) ;
391
399
392
- return propOut . get ( ) ;
400
+ var out = propOut . get ( ) ;
401
+ // in case v was provided but invalid, try the template again so it still
402
+ // overrides the regular default
403
+ if ( template && out === dflt && ! validate ( v , opts ) ) {
404
+ v = nestedProperty ( template , attribute ) . get ( ) ;
405
+ coerceFunction ( v , propOut , dflt , opts ) ;
406
+ out = propOut . get ( ) ;
407
+ }
408
+ return out ;
393
409
} ;
394
410
395
411
/**
@@ -486,7 +502,7 @@ exports.coerceSelectionMarkerOpacity = function(traceOut, coerce) {
486
502
coerce ( 'unselected.marker.opacity' , usmoDflt ) ;
487
503
} ;
488
504
489
- exports . validate = function ( value , opts ) {
505
+ function validate ( value , opts ) {
490
506
var valObjectDef = exports . valObjectMeta [ opts . valType ] ;
491
507
492
508
if ( opts . arrayOk && isArrayOrTypedArray ( value ) ) return true ;
@@ -503,4 +519,5 @@ exports.validate = function(value, opts) {
503
519
504
520
valObjectDef . coerceFunction ( value , propMock , failed , opts ) ;
505
521
return out !== failed ;
506
- } ;
522
+ }
523
+ exports . validate = validate ;
0 commit comments