File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ var buttonsAttrs = {
2727 args : {
2828 valType : 'info_array' ,
2929 role : 'info' ,
30+ freeLength : true ,
3031 items : [
3132 { valType : 'any' } ,
3233 { valType : 'any' } ,
Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ exports.valObjects = {
233233 'An {array} of plot information.'
234234 ] . join ( ' ' ) ,
235235 requiredOpts : [ 'items' ] ,
236- otherOpts : [ 'dflt' ] ,
236+ otherOpts : [ 'dflt' , 'noFixLength' ] ,
237237 coerceFunction : function ( v , propOut , dflt , opts ) {
238238 if ( ! Array . isArray ( v ) ) {
239239 propOut . set ( dflt ) ;
@@ -255,10 +255,11 @@ exports.valObjects = {
255255
256256 var items = opts . items ;
257257
258- if ( v . length !== items . length ) return false ;
258+ // when free length is off, input and declared lengths must match
259+ if ( ! opts . freeLength && v . length !== items . length ) return false ;
259260
260- // valid when all items are valid
261- for ( var i = 0 ; i < items . length ; i ++ ) {
261+ // valid when all input items are valid
262+ for ( var i = 0 ; i < v . length ; i ++ ) {
262263 var isItemValid = exports . validate ( v [ i ] , opts . items [ i ] ) ;
263264
264265 if ( ! isItemValid ) return false ;
Original file line number Diff line number Diff line change @@ -985,6 +985,29 @@ describe('Test lib.js:', function() {
985985 } ]
986986 } ) ;
987987 } ) ;
988+
989+ it ( 'should work for valType \'info_array\' (freeLength case)' , function ( ) {
990+ var shouldPass = [
991+ [ 'marker.color' , 'red' ] ,
992+ [ { 'marker.color' : 'red' } , [ 1 , 2 ] ]
993+ ] ;
994+ var shouldFail = [
995+ [ 'marker.color' , 'red' , 'red' ] ,
996+ [ { 'marker.color' : 'red' } , [ 1 , 2 ] , 'blue' ]
997+ ] ;
998+
999+ assert ( shouldPass , shouldFail , {
1000+ valType : 'info_array' ,
1001+ freeLength : true ,
1002+ items : [ {
1003+ valType : 'any'
1004+ } , {
1005+ valType : 'any'
1006+ } , {
1007+ valType : 'number'
1008+ } ]
1009+ } ) ;
1010+ } ) ;
9881011 } ) ;
9891012
9901013 describe ( 'setCursor' , function ( ) {
You can’t perform that action at this time.
0 commit comments