Hi,
I've got a couple of problems trying to make the following simple xml work:
The associated topnsample.js code is:
require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc) {
var tok = mvc.Components.get('topn_src_ip');
tok.settings.set('_previous_value', tok.val());
tok.on('change', function() {
var val = parseInt("" + this.val());
if (isNaN(val) || val < 1) {
// Invalid user defined value: cancel it by restoring the previous one.
var prev = this.settings.get('_previous_value');
this.val(prev);
return;
}
this.settings.set('_previous_value', val);
var tbl = mvc.Components.get('src_ip_table');
tbl.getVisualization(function(vis) {
vis.settings.set('pageSize', val);
vis.table.render();
});
});
});
Roughly the topn_src_ip drop-down allows the user to dynamically choose how many rows he wants to display in the src_ip_table and the onchange callback adjusts the table's pageSize accordingly.
My first problem is that **the first time** I change the drop-down value from the default one (20) to another predefined value (say 10 for example), I've got a javascript error
"TypeError: i is undefined mvc.js:6:622780" here in the onchange callback:
this.settings.set('_previous_value', val); <= error here
var tbl = mvc.Components.get('src_ip_table');
...
Then the next changes work just well either using predefined values or valid custom ones.
My second problem is that when I enter an invalid custom input in the drop-down, I've got a second error:
"TypeError: e.replace is not a function mvc.js:6:28046" here:
var prev = this.settings.get('_previous_value');
this.val(prev); <= error here
Any idea what's wrong with this code?
Note: I'm running Splunk 6.3.1.
BTW, what's the best way in splunkjs to check custom user values entered in a drop-down for sanity and reject them if they are invalid; leaving the drop-down list of choices unchanged? Is there a callback available for this purpose?
Thanks in advance.
↧