$( document ).ready(function() { .. }) in customPromptTypes.js not executed

We’re trying to run a js function, after a page is loaded. It as intended when I call it from the console. It also works if I add

$( document ).ready(function() {sectionhideshow()});

To the html/handlebar. It does not work if I add this to the customPromptTypes.js

Any ideas?

1 Like

Hi @Simon_Hess! This is not my area of expertise, but from using the customPromptTypes.js, it really is designed for prompts. So I have used it to do things like take a random sample based on the number of students in a classroom through a custom sample prompt. I don’t think it is meant to just run a function without a prompt.

Oh ok. That sounds reasonable. I’m just having a heard time wrapping my head around why this does not work. I think ODK-Xs internals are still a bit of a mystery to me, and the docs are not really helping in this. But thanks for your (frequent) support in solving my issues.

1 Like

I think custom prompt types expose an afterRender property that can be used to trigger functions as you describe. E.g. if you have custom prompts something like this

define(["promptTypes", "jquery", "require"], function (promptTypes, $, r) {
  return {
    example_custom_prompt: promptTypes.input_type.extend({
      templatePath: "some/template/path",
      afterRender: function () {
        // add the code/function you need here to trigger after render

For understanding the internals of the custom prompts I think you can look into the docs for requireJS, or for the HTML files they are rendered using handlebars as you mentioned