surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.2k stars 810 forks source link

Custom widget issue. #1601

Closed kyparyt closed 5 years ago

kyparyt commented 5 years ago

I have an issue with adding custom widget to survey toolbox.

I'm trying to create a component with some logic. For the first i had an issue with components names, but after I've read this article I've decided to create custom widget.

Are you requesting a feature, reporting a bug or asking a question?

Asking a question.

What is the current behavior?

I've already added a widget (according to this example), but when i'm trying to select it from toolbox i have a type error image

What is the expected behavior?

Understand how to add custom widgets into my toolbox, for next usage.

Provide the test code and the tested page URL (if applicable)

Test code Widget code the same as in example;

Adding to toolbar:

    editor.toolbox.addItem({
        name: "customitem",
        category: "Waivers",
        iconName: "icon-text",
        isCopied: false,
        title: "custom item",
        json: {
            type: "textwithbutton",
            name: "q1",
            placeHolder: "put some text here",
            buttonText: "Custom button text"
        },
    });

Specify your

tsv2013 commented 5 years ago

@andrewtelnov Do we need to transfer this issue to the corresponding repository?

andrewtelnov commented 5 years ago

@kyparyt I have added your code into our custom widget example and it works fine. Here is the example

Thank you, Andrew

andrewtelnov commented 5 years ago

@kyparyt You are getting the error, because in your code, for some reason, this line is not executed: Survey.JsonObject.metaData.addClass("textwithbutton", [], null, "text"); It registered a new class in the library.

Thank you, Andrew

kyparyt commented 5 years ago

Thank you. It helped me to find solution for my project ;)