Help needed for creation of custom control

Hello,

I’m currently trying to create my own control and add it to AppStudio.

I already

  • created my own toolbox folder and configured it in AppStudio preferences
  • made a copy of the original “Toolbox.json” file (and removed unnecessary categories or added my own control category)
  • set up a trivial control with static (literal) “_htmltemplate” and saved the associated “.json” file in a subfolder of my own toolbox folder

After restarting AppStudio, everything worked as desired.

But now I would like to add my own (JS) code and let “_htmltemplate” invoke a function - and that fails because AppStudio does not find the file I mentioned in “_requiredfiles”!

The actual error message I get in the IDE whenever I try to add my new custom control to a form looks like

with varying paths depending on what I’m currently trying…

PS: everything works fine if I specify the full absolute file path in “_requiredfiles” - but that’s something I would like to avoid and use Toolbox-relative paths instead.

Is there a list of AppStudio variables with some explanation? (e.g., what is the meaning of “_nsbdir”? is it the web apps folder? or that of the toolbox folder(s)?)

Or even better: is there an explanation of how to add one’s own controls?

Thanks in advance for any help!

With greetings from Germany,

Andreas Rozek

It sounds like you’re making good progress. Did you see this document?

https://wiki.appstudio.dev/ToolBox_Files

Reading your other questions on the forum, I see you have indeed discovered that document.

For _htmltemplate to call a function, that function needs to have been loaded already. _requiredFiles is a list of the files which need to be loaded.

If you run your app in Chrome and do View Source, you can see how it is loading the additional JavaScript.

I should have been more precise with my question:

given a folder X, which has been configured as a “Toolbox Path” in AppStudio “Preferences”, what is the proper way to reference a file Z located in subfolder Y of X such that AppStudio is able to copy that file during the design/build process?

  • “_requiredfiles”: [ “{_nsbdir}Y/Z” ], or
  • “_requiredfiles”: [ “{_nsbdir}toolbox/Y/Z” ],

will all fail.

Just to be complete:

  • the author’s modified version of X/Toolbox.json is found and respected,
  • additional *.json files in subfolders of X are found and respected

but neither any *.js nor *.css file is.

PS: I’ve been able to use a URL for “_requiredfiles” (referring to a file served by a web server) which shows me that my JS is correct - but now I would like to refer to a local file. How can I achieve that?

The path in _requiredfiles should be where the file is found at run time. If it’s in the top level of your project, Z.js should work fine.

…but the AppStudio toolbox also contains (.png, .js, .css) files (some of them in subdirectories) which are “required” by other .json files - how do they get copied to the project? This happens automatically, and I would like to exploit that mechanism for my own custom controls.

Better tell me more about what you’re trying to do. I’ll be able to give more specific advice.

Feel free to email me directly.