OpenJSCAD.org icon indicating copy to clipboard operation
OpenJSCAD.org copied to clipboard

Params callback functions

Open ErikDeBruijn opened this issue 11 years ago • 4 comments

Perhaps it's a good idea to allow callback functions or at least regexes to validate content passed through the parameters div input controls or for the ones passed by URL. This will prevent parse errors in many cases. Right now javascript errors are thrown, but it's better to allow people to define friendly messages, perhaps even things like "The wall thickness cannot be negative".

{
  name: 'shape',
  type: 'choice',
  values: ["TRI", "SQU", "CIR"],               // these are the values that will be supplied to your script
  captions: ["Triangle", "Square", "Circle"],  // optional, these values are shown in the listbox
                                               // if omitted, the items in the 'values' array are used
  caption: 'Shape:',                           // optional, displayed left of the input field
  initial: "SQU",                              // optional, default selected value
                                               // if omitted, the first item is selected by default
                                               // NOTE: parameter "default" is deprecated
  validate: shapeValidate
}

An example to clarify:

function validate(parameterDefinitions,paramName,paramValue){
if(paramValue == "circular") && parameterDefinitions['height'].value > 10)
  status("The "+paramValue+" shape can only be used when the height is more than 10.");
}

ErikDeBruijn avatar Sep 24 '14 02:09 ErikDeBruijn

This issue was opened in 2014, had some commits but no recent activity for past 2 years. And it's not a bug. I suggest we close it as stale.

paulftw avatar Dec 20 '21 14:12 paulftw

Actually, there was also a request in discord for a way the script can produce some output aside from model. For example users are creating utility scripts where it is useful to show the user some calculation details. In current V2 throwing an error for invalid params would display the message on the screen in red.

hrgdavor avatar Dec 20 '21 14:12 hrgdavor

Let’s let @ErikDeBruijn decide to close. There’s no solution yet.

z3dev avatar Dec 21 '21 00:12 z3dev

I don't have a strong need for this anymore but if my request is useful to others we can keep it alive. Im fine with focus on other, more recent feature requests, though! Perhaps that is time better spent.

ErikDeBruijn avatar Jan 07 '22 20:01 ErikDeBruijn