There is a need to access an answer from a previous step from a Page type. Currently, this is possible from a Question type. Unfortunately, it is not possible from Page, ExitPoint, etc.
The below is a workaround provided by @michaeldfallen to achieve this. However, it requires being running the 2.0.0-1 version.
const { form, textField } = require('@hmcts/one-per-page/forms');
const { Page } = require('@hmcts/one-per-page');
const paths = require('paths');
class FormDownload extends Page {
get url() {
return paths.formDownload;
}
get benefitType() {
const fields = form(textField.ref(this.journey.BenefitType, 'benefitType')).bind(this).retrieve(this.req);
console.log(`benefitType: ${fields.fields[0].value}`);
}
}
module.exports = FormDownload;
Therefore, for the time being, we will meet this requirement by extending from the Question type and later on once we upgrade to the 2.0.0-1 version we will refactor this work to extend from the Page type and use the code provided by Michael here. He suggested providing a cleaner way to do it as well.
I use this issue ticket to make a note of this work and discussion between him and me.
There is a need to access an answer from a previous step from a Page type. Currently, this is possible from a Question type. Unfortunately, it is not possible from Page, ExitPoint, etc.
The below is a workaround provided by @michaeldfallen to achieve this. However, it requires being running the 2.0.0-1 version.
Therefore, for the time being, we will meet this requirement by extending from the Question type and later on once we upgrade to the 2.0.0-1 version we will refactor this work to extend from the Page type and use the code provided by Michael here. He suggested providing a cleaner way to do it as well.
I use this issue ticket to make a note of this work and discussion between him and me.