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

The Skip To trigger immediatelly navigates to another question when s… #6795

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5460,7 +5460,7 @@ export class SurveyModel extends SurveyElementCore
private isTriggerIsRunning: boolean = false;
private triggerValues: any = null;
private triggerKeys: any = null;
private checkTriggers(key: any, isOnNextPage: boolean, isOnComplete: boolean = false) {
private checkTriggers(key: any, isOnNextPage: boolean, isOnComplete: boolean = false, name?: string) {
if (this.isCompleted || this.triggers.length == 0 || this.isDisplayMode) return;
if (this.isTriggerIsRunning) {
this.triggerValues = this.getFilteredValues();
Expand All @@ -5469,13 +5469,20 @@ export class SurveyModel extends SurveyElementCore
}
return;
}
let isQuestionInvalid = false;
if(!isOnComplete && name && this.hasRequiredValidQuestionTrigger) {
const question = <Question>this.getQuestionByValueName(name);
isQuestionInvalid = question && !question.validate(false);
}
this.isTriggerIsRunning = true;
this.triggerKeys = key;
this.triggerValues = this.getFilteredValues();
var properties = this.getFilteredProperties();
let prevCanBeCompleted = this.canBeCompletedByTrigger;
for (var i: number = 0; i < this.triggers.length; i++) {
this.triggers[i].checkExpression(isOnNextPage, isOnComplete,
for (let i = 0; i < this.triggers.length; i++) {
const trigger = this.triggers[i];
if(isQuestionInvalid && trigger.requireValidQuestion) continue;
trigger.checkExpression(isOnNextPage, isOnComplete,
this.triggerKeys,
this.triggerValues,
properties
Expand All @@ -5486,6 +5493,12 @@ export class SurveyModel extends SurveyElementCore
}
this.isTriggerIsRunning = false;
}
private get hasRequiredValidQuestionTrigger(): boolean {
for (let i = 0; i < this.triggers.length; i++) {
if(this.triggers[i].requireValidQuestion) return true;
}
return false;
}
private doElementsOnLoad() {
for (var i = 0; i < this.pages.length; i++) {
this.pages[i].onSurveyLoad();
Expand Down Expand Up @@ -6117,7 +6130,7 @@ export class SurveyModel extends SurveyElementCore
var triggerKeys: { [index: string]: any } = {};
triggerKeys[name] = { newValue: newValue, oldValue: oldValue };
this.runConditionOnValueChanged(name, newValue);
this.checkTriggers(triggerKeys, false);
this.checkTriggers(triggerKeys, false, false, name);
if (allowNotifyValueChanged)
this.notifyQuestionOnValueChanged(name, newValue);
if (locNotification !== "text") {
Expand Down
3 changes: 3 additions & 0 deletions src/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class Trigger extends Base {
this.onFailure();
}
}
public get requireValidQuestion(): boolean { return false; }
private perform(values: HashTable<any>, properties: HashTable<any>) {
this.conditionRunner.onRunComplete = (res: boolean) => {
this.triggerResult(res, values, properties);
Expand Down Expand Up @@ -299,6 +300,7 @@ export class SurveyTriggerComplete extends SurveyTrigger {
public getType(): string {
return "completetrigger";
}
public get requireValidQuestion(): boolean { return true; }
protected isRealExecution(): boolean {
return !settings.triggers.executeCompleteOnValueChanged === this.isExecutingOnNextPage;
}
Expand Down Expand Up @@ -368,6 +370,7 @@ export class SurveyTriggerSkip extends SurveyTrigger {
public getType(): string {
return "skiptrigger";
}
public get requireValidQuestion(): boolean { return this.canBeExecuted(false); }
public get gotoName(): string {
return this.getPropertyValue("gotoName", "");
}
Expand Down
81 changes: 81 additions & 0 deletions tests/surveytriggertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,84 @@ QUnit.test("Show complete button instead of next for single matrix, bug#6152", f
assert.equal(survey.isShowNextButton, false, "#7-next");
assert.equal(survey.isCompleteButtonVisible, true, "#7-complete");
});
QUnit.test("skip trigger for showOtherItem, Bug#6792", function (assert) {
const survey = new SurveyModel({
"pages": [
{
"name": "page1",
"elements": [
{
"type": "radiogroup",
"name": "question1",
"choices": [
"Item 1",
"Item 2",
"Item 3"
],
"showOtherItem": true
}
]
},
{
"name": "page2",
"elements": [
{
"type": "boolean",
"name": "question2"
}
]
}
],
"triggers": [
{
"type": "skip",
"expression": "{question1} notempty",
"gotoName": "question2"
}
] });
const q1 = survey.getQuestionByName("question1");
q1.value = "other";
assert.equal(survey.currentPageNo, 0, "We are staying on the same page");
});
QUnit.test("complete trigger for showOtherItem, Bug#6792", function (assert) {
const oldSettings = settings.triggers.executeCompleteOnValueChanged;
settings.triggers.executeCompleteOnValueChanged = true;
const survey = new SurveyModel({
"pages": [
{
"name": "page1",
"elements": [
{
"type": "radiogroup",
"name": "question1",
"choices": [
"Item 1",
"Item 2",
"Item 3"
],
"showOtherItem": true
}
]
},
{
"name": "page2",
"elements": [
{
"type": "boolean",
"name": "question2"
}
]
}
],
"triggers": [
{
"type": "complete",
"expression": "{question1} notempty"
}
] });
const q1 = survey.getQuestionByName("question1");
q1.value = "other";
assert.equal(survey.currentPageNo, 0, "We are staying on the same page");
assert.equal(survey.state, "running", "Survey is not completed");
settings.triggers.executeCompleteOnValueChanged = oldSettings;
});