Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce survey.onAfterRenderQuestionInput event #2032

Closed
andrewtelnov opened this issue Mar 16, 2020 · 0 comments
Closed

Introduce survey.onAfterRenderQuestionInput event #2032

andrewtelnov opened this issue Mar 16, 2020 · 0 comments

Comments

@andrewtelnov
Copy link
Member

@andrewtelnov andrewtelnov commented Mar 16, 2020

Right now to set a event to a DOM element requires to handle several events and write a different code, in case if you want to change the rendering, for example, for text input in Text Question, Multiple Text Question and in matrices (dropdown and dynamic).
By introducing survey.onAfterRenderQuestionInput will allow to update DOM element for questions that uses as stanalone questions (text, dropdown and so on) and in composite questions: multiple text and matrices.
Here is the example of suspending to type 'e' letter for number input.

survey.onAfterRenderQuestionInput.add(function(sender, options) {
  if (options.question.getType() === "text") {
    if (options.question.inputType === "number") {
      options.htmlElement.addEventListener("keypress", function(evt) {
        if (
          (evt.which != 8 &&
            evt.which != 0 &&
            evt.which != 46 &&
            evt.which < 48) ||
          evt.which > 57
        ) {
          evt.preventDefault();
        }
      });
    }
  }
});

Here is the survey JSON. It will apply for all input elements in this survey.

var json = {
  elements: [
    {
      type: "text",
      name: "q1",
      inputType: "number"
    },
    {
      type: "multipletext",
      name: "q2",
      items: [
        { name: "item1", inputType: "number" },
        { name: "item2", inputType: "number" }
      ]
    },
    {
      type: "matrixdynamic",
      name: "q3",
      rowCount: 2,
      columns: [
        {
          name: "col1",
          cellType: "text",
          inputType: "number"
        }
      ]
    }
  ]
};
@andrewtelnov andrewtelnov added this to the v1.5.16 milestone Mar 16, 2020
andrewtelnov added a commit that referenced this issue Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.