0

Custom parameters in a CDE/CTools dashboard are great for defaulting initial values of parameters, e.g. setting a date parameter to today. i.e. the parameter looks like:

function() { // some code return val }

However there is an issue with them. The first time you access a "custom parameter" in code, it is a function not a string. So you have to use:

paramName()

To get its value.

Once the end user selects a value then you have to use

paramName

This is really awkward in complicated dashboards with lots of prompts. Is there a better way this can be done? (Perhaps there is something in javascript I'm missing to help here?)

mzy
  • 1,754
  • 2
  • 20
  • 36
Codek
  • 5,114
  • 3
  • 24
  • 38
  • I don't use the dashboards, but what happens if you use paranName() after the value is selected? – Brian.D.Myers Sep 05 '13 at 20:18
  • you get a javascript error because you're trying to make a function call on something that is actually a string – Codek Sep 06 '13 at 14:54
  • 1
    you don't need to wrap it in a function. Whatever Javascript you put there will be evaluated and its return value will be used as parameter's value. E.g.: `['january', 'february', ..., 'december'][(new Date()).getMonth()]` will return the current month's name. – Óscar Gómez Alcañiz Nov 24 '16 at 15:29

1 Answers1

2

OK, there is a solution, but I dont like it!

First; Move all the init code into named procedures e.g.

function monthInit() { return "june"; }

Then in the custom parameter for month, just say:

monthInit();

That way the custom parameter is always a string, and never starts off as a function.

Not ideal though because then all your init code is in a separate bit of js.

Codek
  • 5,114
  • 3
  • 24
  • 38