Skip to content

Commit

Permalink
Scroll to the first question generated an error: #20
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jun 13, 2016
1 parent e5fa14c commit 41009fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/knockout/templates/question.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script type="text/html" id="survey-question">
<div data-bind="visible: question.koVisible(), css: $root.css.question.root">
<div data-bind="visible: question.koVisible(), css: $root.css.question.root, attr: {id: id}">
<!-- ko if: question.hasTitle -->
<h5 data-bind="text: question.koNo() + (question.isRequired ? question.requiredText : '') + question.processedTitle, css: $root.css.question.title"></h5>
<!-- /ko -->
Expand Down
11 changes: 11 additions & 0 deletions src/questionbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
/// <reference path="jsonobject.ts" />
module Survey {
export class QuestionBase extends Base implements IQuestion {
private static questionCounter = 100;
private static getQuestionId(): string {
return "sq_" + QuestionBase.questionCounter++;
}
protected data: ISurvey;
private idValue: string;
private visibleValue: boolean = true;
private visibleIndexValue: number = -1;
public width: string = "100%";
Expand All @@ -12,6 +17,7 @@ module Survey {

constructor(public name: string) {
super();
this.idValue = QuestionBase.getQuestionId();
this.onCreating();
}
public get visible(): boolean { return this.visibleValue; }
Expand All @@ -27,7 +33,12 @@ module Survey {
public hasErrors(): boolean { return false; }
public get hasTitle(): boolean { return false; }
public get hasComment(): boolean { return false; }
public get id(): string { return this.idValue; }
public focus() {
var el = document.getElementById(this.id);
if (!!el && el.scrollIntoView) {
el.scrollIntoView();
}
this.fireCallback(this.focusCallback);
}
setData(newValue: ISurvey) {
Expand Down
2 changes: 1 addition & 1 deletion src/react/reactquestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ReactSurveyQuestion extends React.Component<any, any> {
var comment = (this.question && this.question.hasComment) ? this.renderComment() : null;
var errors = (this.question && this.question.errors.length > 0) ? this.renderErrors() : null;
return (
<div className={this.css.question.root}>
<div id={this.questionBase.id} className={this.css.question.root}>
{title}
{errors}
{questionRender}
Expand Down

0 comments on commit 41009fc

Please sign in to comment.