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 = {
27
27
args : {
28
28
valType : 'info_array' ,
29
29
role : 'info' ,
30
+ freeLength : true ,
30
31
items : [
31
32
{ valType : 'any' } ,
32
33
{ valType : 'any' } ,
Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ exports.valObjects = {
233
233
'An {array} of plot information.'
234
234
] . join ( ' ' ) ,
235
235
requiredOpts : [ 'items' ] ,
236
- otherOpts : [ 'dflt' ] ,
236
+ otherOpts : [ 'dflt' , 'noFixLength' ] ,
237
237
coerceFunction : function ( v , propOut , dflt , opts ) {
238
238
if ( ! Array . isArray ( v ) ) {
239
239
propOut . set ( dflt ) ;
@@ -255,10 +255,11 @@ exports.valObjects = {
255
255
256
256
var items = opts . items ;
257
257
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 ;
259
260
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 ++ ) {
262
263
var isItemValid = exports . validate ( v [ i ] , opts . items [ i ] ) ;
263
264
264
265
if ( ! isItemValid ) return false ;
Original file line number Diff line number Diff line change @@ -985,6 +985,29 @@ describe('Test lib.js:', function() {
985
985
} ]
986
986
} ) ;
987
987
} ) ;
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
+ } ) ;
988
1011
} ) ;
989
1012
990
1013
describe ( 'setCursor' , function ( ) {
You can’t perform that action at this time.
0 commit comments