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.12k stars 802 forks source link

Question: how to know when a calculated text changes #7945

Closed SamMousa closed 3 months ago

SamMousa commented 6 months ago

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

Question / proposal

What is the current behavior?

Say I'm implementing a custom question type. The question type has a property, for example buttonTitle. I want to support placeholders for this property.

I can access the value using calculatedText, but I cannot know when this value might have changed.

How do I know when the calculated text has changed?

JaneSjs commented 6 months ago

Hi @SamMousa, Please accept my apologies for the delayed reply. From what I gather, you wish to create a custom property and define a custom property's placeholder. The placeholder text should appear in a SurveyJS Creator's Property Grid. If so, you can register a custom property grid editor within the PropertyGridEditorCollection (View Demo). Define a placeholder for the custom property grid editor. Consider the following sample demo:

Survey.Serializer.addProperty("question", { 
    name: "buttontitle",
    type: "customstrng",
    displayName: "Button Title",
    category: "general",
    visibleIndex: 3
});

SurveyCreatorCore.PropertyGridEditorCollection.register({
    fit: function(prop) {
        return prop.type === "customstrng";
    },
    getJSON: function(obj,  prop,options) {
        return { 
            type: "text", 
            placeholder: "Enter a button title"
        }
    }
});

View Plunker Let me know if this option may suit you.