Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Oct 9, 2024
2 parents 89baccc + 8c6e29e commit c678658
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 29 deletions.
4 changes: 3 additions & 1 deletion packages/survey-core/src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ export interface ISurvey extends ITextProcessor, ISurveyErrorOwner {
question: IQuestion,
page: IPage,
id: string, scrollIfVisible?: boolean,
scrollIntoViewOptions?: ScrollIntoViewOptions
scrollIntoViewOptions?: ScrollIntoViewOptions,
passedRootElement?: HTMLElement,
onScolledCallback?: () => void
): any;
runExpression(expression: string, callback?: (res: any) => void): any;
elementContentVisibilityChanged(element: ISurveyElement): void;
Expand Down
17 changes: 9 additions & 8 deletions packages/survey-core/src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1244,15 +1244,16 @@ export class Question extends SurveyElement<Question>
if (shouldChangePage) {
this.survey.focusQuestionByInstance(this, onError);
} else {
this.focuscore(onError, scrollIfVisible);
}
}
private focuscore(onError: boolean = false, scrollIfVisible?: boolean): void {
if (!!this.survey) {
this.expandAllParents();
this.survey.scrollElementToTop(this, this, null, this.id, scrollIfVisible);
if (!!this.survey) {
this.expandAllParents();
const scrollOptions: ScrollIntoViewOptions = (this.survey as SurveyModel)["isSmoothScrollEnabled"] ? { behavior: "smooth" } : undefined;
this.survey.scrollElementToTop(this, this, null, this.id, scrollIfVisible, scrollOptions, undefined, () => {
this.focusInputElement(onError);
});
} else {
this.focusInputElement(onError);
}
}
this.focusInputElement(onError);
}
focusInputElement(onError: boolean): void {
const id = !onError ? this.getFirstInputElementId() : this.getFirstErrorInputElementId();
Expand Down
5 changes: 2 additions & 3 deletions packages/survey-core/src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1702,9 +1702,8 @@ export class QuestionPanelDynamicModel extends Question
: null;
}
public addConditionObjectsByContext(objects: Array<IConditionObject>, context: any): void {
const hasContext = !!context
? context === true || this.template.questions.indexOf(context) > -1
: false;
const contextQ = !!context?.isValidator ? context.errorOwner : context;
const hasContext = !!context && (context === true || this.template.questions.indexOf(contextQ) > -1);
const panelObjs = new Array<IConditionObject>();
const questions = this.template.questions;
for (var i = 0; i < questions.length; i++) {
Expand Down
19 changes: 6 additions & 13 deletions packages/survey-core/src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,6 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
requestAnimationFrame(checkPos);
};
DomWindowHelper.requestAnimationFrame(checkPos);
// let currPageXOffset = window.pageXOffset;
// let currPageYOffset = window.pageYOffset;
// var scrollDone = setInterval(() => {
// DomWindowHelper.requestAnimationFrame(() => {
// if (currPageXOffset == window.pageXOffset && currPageYOffset == window.pageYOffset) {
// clearInterval(scrollDone);
// doneCallback();
// }
// currPageXOffset = window.pageXOffset;
// currPageYOffset = window.pageYOffset;
// });
// }, 25);
}
}
public static ScrollElementToTop(elementId: string, scrollIfVisible?: boolean, scrollIntoViewOptions?: ScrollIntoViewOptions, doneCallback?: () => void): boolean {
Expand All @@ -246,10 +234,15 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
return SurveyElement.ScrollElementToViewCore(el, false, scrollIfVisible, scrollIntoViewOptions, doneCallback);
}
public static ScrollElementToViewCore(el: HTMLElement, checkLeft: boolean, scrollIfVisible?: boolean, scrollIntoViewOptions?: ScrollIntoViewOptions, doneCallback?: () => void): boolean {
if (!el || !el.scrollIntoView) return false;
if (!el || !el.scrollIntoView) {
doneCallback && doneCallback();
return false;
}
const needScroll = SurveyElement.IsNeedScrollIntoView(el, checkLeft, scrollIfVisible);
if (needScroll) {
SurveyElement.ScrollIntoView(el, scrollIntoViewOptions, doneCallback);
} else {
doneCallback && doneCallback();
}
return needScroll;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4906,6 +4906,7 @@ export class SurveyModel extends SurveyElementCore
.append(this.css.rootFitToContainer, this.fitToContainer)
.toString();
}
private isSmoothScrollEnabled = false;
private resizeObserver: ResizeObserver;
afterRenderSurvey(htmlElement: any) {
this.destroyResizeObserver();
Expand Down Expand Up @@ -5289,7 +5290,8 @@ export class SurveyModel extends SurveyElementCore
scrollElementToTop(
element: ISurveyElement, question: Question, page: PageModel,
id: string, scrollIfVisible?: boolean, scrollIntoViewOptions?: ScrollIntoViewOptions,
passedRootElement?: HTMLElement
passedRootElement?: HTMLElement,
onScolledCallback?: () => void
): any {
const options: ScrollingElementToTopEvent = {
element: element,
Expand All @@ -5313,10 +5315,11 @@ export class SurveyModel extends SurveyElementCore
SurveyElement.ScrollElementToTop(options.elementId, scrollIfVisible, scrollIntoViewOptions, () => {
this.releaseLazyRendering();
activateLazyRenderingChecks(elementPage.id);
onScolledCallback && onScolledCallback();
});
}, elementsToRenderBefore);
} else {
SurveyElement.ScrollElementToTop(options.elementId, scrollIfVisible, scrollIntoViewOptions);
SurveyElement.ScrollElementToTop(options.elementId, scrollIfVisible, scrollIntoViewOptions, onScolledCallback);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/survey-core/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class SurveyValidator extends Base {
super();
this.createLocalizableString("text", this, true);
}
public get isValidator(): boolean { return true; }
public getSurvey(live: boolean = false): ISurvey {
return !!this.errorOwner && !!(<any>this.errorOwner)["getSurvey"]
? (<any>this.errorOwner).getSurvey()
Expand Down
19 changes: 19 additions & 0 deletions packages/survey-core/tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,25 @@ QUnit.test("panelDynamic.addConditionObjectsByContext", function(assert) {
"addConditionObjectsByContext work correctly for panel dynamic with context equals true"
);
});
QUnit.test("panelDynamic.addConditionObjectsByContext && question validator, Bug#8914", function(assert) {
const objs = [];
const panel = new QuestionPanelDynamicModel("qPanel");
const q1 = panel.template.addNewQuestion("text", "q1");
q1.validators.push(new ExpressionValidator());
panel.template.addNewQuestion("text", "q2");
panel.addConditionObjectsByContext(objs, q1.validators[0]);
updateObjsQuestions(objs);
assert.deepEqual(
objs,
[
{ name: "qPanel[0].q1", text: "qPanel[0].q1", question: "q1" },
{ name: "qPanel[0].q2", text: "qPanel[0].q2", question: "q2" },
{ name: "panel.q1", text: "panel.q1", question: "q1", context: "qPanel" },
{ name: "panel.q2", text: "panel.q2", question: "q2", context: "qPanel" }
],
"addConditionObjectsByContext work correctly for panel dynamic"
);
});
QUnit.test("panelDynamic.getNestedQuestions", function(assert) {
const panel = new QuestionPanelDynamicModel("qPanel");
panel.template.addNewQuestion("text", "q1");
Expand Down
6 changes: 4 additions & 2 deletions src/entries/js-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ function doPopupSurvey(props: any): void {
});
}

let jQueryInst = window["jQuery"] || window["$"];
let gcontext = globalThis;
if (typeof globalThis === "undefined") gcontext = window;
let jQueryInst = gcontext["jQuery"] || gcontext["$"];

if (typeof jQueryInst !== "undefined") {
initJquery(jQueryInst);
Expand Down Expand Up @@ -107,4 +109,4 @@ export { SurveyModel as Model } from "survey-core";

import { checkLibraryVersion } from "survey-core";

checkLibraryVersion(`${process.env.VERSION}`, "survey-js-ui");
checkLibraryVersion(`${process.env.VERSION}`, "survey-js-ui");
1 change: 1 addition & 0 deletions testCafe/survey/focusFirstQuestionAutomatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ frameworks.forEach(async framework => {
await t.expect(panel1_q1Sel.filter(filterIsInViewport).exists).ok()
.pressKey("a");
await focusQuestion("q1", false);
await t.wait(1000);
await t.expect(q1Sel.filter(filterIsInViewport).exists).ok()
.pressKey("b");
await focusQuestion("panel1_q1", true);
Expand Down

0 comments on commit c678658

Please sign in to comment.