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

Add onAfterRender* events to Survey model. #219

Closed
andrewtelnov opened this issue Feb 3, 2017 · 6 comments
Closed

Add onAfterRender* events to Survey model. #219

andrewtelnov opened this issue Feb 3, 2017 · 6 comments

Comments

@andrewtelnov
Copy link
Member

andrewtelnov commented Feb 3, 2017

There are tasks that require to modify generated DOM elements after rendering.
Three new events: onAfterRenderSurvey, onAfterRenderPage and onAfterRenderQuestion are needed.
The options will contains two parameters: survey or page or question objects and htmlElement - a DOM element that associates with the model object.

@andrewtelnov andrewtelnov changed the title Add afterRender* events to Survey model. Add onAfterRender* events to Survey model. Feb 3, 2017
@andrewtelnov
Copy link
Member Author

Implemented. An exampled needed.

@ryancwalsh
Copy link

I'm very excited about this!

Here is an example of how I'm using it:

surveyModel.onAfterRenderQuestion.add(function (sender, options) {
        console.log('onAfterRenderQuestion options', options);
        if (options.question.name === 'initiate') {
            colorizeItems($('label.radio'));
        } else {
            $('label.radio').removeAttr('style');
        }
    });

@andrewtelnov
Copy link
Member Author

@ryancwalsh You may want to use options.htmlElement. It is the htmlElement for this question. In this case you may modify the DOM of this element and its children.

Thank you,
Andrew

@ryancwalsh
Copy link

@andrewtelnov Cool, thanks!

Here is what I'm using now:

    surveyModel.onAfterRenderQuestion.add(function (sender, options) {
        console.log('onAfterRenderQuestion options', options);
        if (options.question.name === 'initiate') {
            colorizeItems($(options.htmlElement).find('label.radio'));
        } else {
            $(options.htmlElement).find('label.radio').removeAttr('style');
        }
    });

It seems like the else is required since the templating reuses the label DOM elements on future pages/questions.

That's how I got it to behave how I wanted.

Thanks.

@andrewtelnov
Copy link
Member Author

@ryancwalsh Cool!

Thank you,
Andrew

@andrewtelnov
Copy link
Member Author

The better way is to use the custom widget feature with isDefaultRender set to true.
Here is the demo: http://surveyjs.org/examples/jquery/custom-widget-barrating.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants