-
Notifications
You must be signed in to change notification settings - Fork 839
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
Trigger changed between 1.12.15 and 1.12.16 #9376
Comments
Update, it might have been fixed in .18, I'll keep checking each version. (.21 its broken). Edit: my test case is fixed in .18, but actually doing the survey manually does not fix it. import { SurveyModel, Serializer, SurveyTriggerComplete } from 'survey-core';
import screenoutTrigger from './screenoutTrigger';
describe('Trigger works properly', async() => {
await screenoutTrigger(Serializer, SurveyTriggerComplete)
it('Screenout in questionOnPageMode', async () => {
const survey = new SurveyModel({
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "info",
"title": "Info text"
},
{
"type": "checkbox",
"name": "question1",
"isRequired": true,
"choices": [
{
"value": "Item 1",
"text": "kort"
},
{
"value": "Item 2",
"text": "middellang",
"info": "{info}"
}
],
"showOtherItem": true
}
]
},
{
"name": "page2",
"elements": [
{
"type": "rating",
"name": "question2",
"rateType": "smileys"
}
]
}
],
"triggers": [
{
"type": "screenout",
"expression": "{info} = 'test'"
}
],
"questionsOnPageMode": "questionPerPage"
});
expect(survey.triggers[0]).not.toBeNull();
let executed = false;
survey.onTriggerExecuted.add(() => {
executed = true;
})
survey.setValue('info', 'test');
// expect(survey.isSingleVisibleQuestion).toBeTruthy();
expect(survey.nextPage()).toBeTruthy();
expect(executed).toBeTruthy();
});
it('Complete in questionOnPageMode', async () => {
const survey = new SurveyModel({
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "info",
"title": "Info text"
},
{
"type": "checkbox",
"name": "question1",
"isRequired": true,
"choices": [
{
"value": "Item 1",
"text": "kort"
},
{
"value": "Item 2",
"text": "middellang",
"info": "{info}"
}
],
"showOtherItem": true
}
]
},
{
"name": "page2",
"elements": [
{
"type": "rating",
"name": "question2",
"rateType": "smileys"
}
]
}
],
"triggers": [
{
"type": "complete",
"expression": "{info} = 'test'"
}
],
"questionsOnPageMode": "questionPerPage"
});
expect(survey.triggers[0]).not.toBeNull();
let executed = false;
survey.onTriggerExecuted.add(() => {
executed = true;
})
survey.setValue('info', 'test');
// expect(survey.isSingleVisibleQuestion).toBeTruthy();
expect(survey.nextPage()).toBeTruthy();
expect(executed).toBeTruthy();
});
it('Complete in standard mode', async () => {
const survey = new SurveyModel({
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "info",
"title": "Info text"
},
{
"type": "checkbox",
"name": "question1",
"isRequired": false,
"choices": [
{
"value": "Item 1",
"text": "kort"
},
{
"value": "Item 2",
"text": "middellang",
"info": "{info}"
}
],
"showOtherItem": true
}
]
},
{
"name": "page2",
"elements": [
{
"type": "rating",
"name": "question2",
"rateType": "smileys"
}
]
}
],
"triggers": [
{
"type": "complete",
"expression": "{info} = 'test'"
}
],
"questionsOnPageMode": "standard"
});
expect(survey.triggers[0]).not.toBeNull();
let executed = false;
survey.onTriggerExecuted.add(() => {
executed = true;
})
survey.setValue('info', 'test');
// expect(survey.isSingleVisibleQuestion).toBeTruthy();
expect(survey.nextPage()).toBeTruthy();
expect(executed).toBeTruthy();
});
}); |
@SamMousa Please let me write the unit test and fix it. I pretty sure the issue is still here. We do not have tests for this case after we stop creating pages for every question on the fly for this mode. Thank you, |
@SamMousa I wrote the unit test and it works. I have checked it with the latest version and again it works. Thank you, |
I can repro that too, but there is definitely a change in behavior. import type { HashTable, JsonMetadata } from 'survey-core';
import type { SurveyTriggerComplete as SurveyTriggerCompleteType } from 'survey-core';
export const editorLocalizationStrings = {
lg: {
trigger_screenoutName: 'Screenout',
trigger_screenoutText: 'the response will be marked as a screenout',
trigger_screenoutDescription: 'Marks the response as a screenout and exits the survey'
}
};
export default (
serializer: JsonMetadata,
SurveyTriggerComplete: typeof SurveyTriggerCompleteType
) => {
class ScreenoutTrigger extends SurveyTriggerComplete {
getType() {
return 'screenouttrigger';
}
protected onSuccess(values: HashTable<unknown>, properties: HashTable<unknown>): void {
console.log('screenoutTrigger', 'onSuccess', this.isRealExecution(), super.isRealExecution());
if (this.isRealExecution()) {
this.owner.setTriggerValue('result', 'screenout', false);
// Parent call
super.onSuccess(values, properties);
}
}
}
serializer.addClass('screenouttrigger', [], () => new ScreenoutTrigger(), 'completetrigger');
}; Could it be that there is special handling for the |
@SamMousa Yes, it could be. I will check it out tomorrow. Thank you, |
https://plnkr.co/edit/4pjv1jWKwrTtKD35 I have updated the plunker, it shows that:
Edit:
|
I've been thinking on this, and maybe the best way forward is not to try and fix everything... What we're missing to be able to update our features are ways to hook into the new logic:
I'm happy to implement changes to our code if it makes your code cleaner. |
@SamMousa Here is your updated example. // Parent call
super.onSuccess(values, properties); Thank you, |
I have added the related unit test for your case by this commit. Thank you, |
I'll close this and extract the event based stuff in a new issue. |
Describe the bug
We have a custom trigger that extends SurveyCompleteTrigger:
This is the survey JSON:
Steps to reproduce
test
into the first questionIn version 2.11.15 the trigger code is executed twice, once onblur, with
isRealExecution()
false
. The second time withtrue
.In version 2.11.16 the second execution with
isRealExecution() === true
does not happen when navigation is set toquestionPerPage
.The changes between 2.11.15 and 2.11.16 are enormous (very nice job btw on the addition of typing) -- but somewhere in those changes is a change of behavior.
The text was updated successfully, but these errors were encountered: