diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 475c630c86e8664ce74bdfcef850275bd4f32a67..f2141323a49d79f1ff4fee955ce54213479efdf7 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -25,6 +25,7 @@ import { ServiceFactory } from "../../services/service-factory"; import { SelectEntry } from "../elements/select/select-entry"; import { SelectField } from "../elements/select/select-field"; import { DeepSelectFieldIterator } from "../form-iterator/deep-selectfield-iterator"; +import { ConfigParser } from "./config-parser"; /** * classe de base pour tous les formulaires @@ -146,6 +147,24 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs Session.getInstance().deleteNub(sn); } + /** + * parse calculator JSON configuration for select default value + * @param selectId select id, ie. "id" field value + * @return select "default" field value + */ + protected parseSelectDefaultValue(json: {}, selectId: string): string { + const jp = new ConfigParser(json); + for (const fs of jp.forAll("fieldset")) { + const fsp = new ConfigParser(fs["fields"]); + for (const sel of fsp.forAll("select")) { + if (sel["id"] === selectId) { + return sel["default"]; + } + } + } + return undefined; + } + /** * prepare options parsing */ diff --git a/src/app/formulaire/definition/form-section.ts b/src/app/formulaire/definition/form-section.ts index 7ef1534e104c6b2a3193dfcdca657222c03f016e..8f8be0af96d577110333fe270c861ec7297c621f 100644 --- a/src/app/formulaire/definition/form-section.ts +++ b/src/app/formulaire/definition/form-section.ts @@ -3,7 +3,6 @@ import { FieldSet } from "../elements/fieldset"; import { ServiceFactory } from "../../services/service-factory"; import { IObservable, Session, SectionNub, Props, CalculatorType, Prop_NullParameters, acSection } from "jalhyd"; -import { ConfigParser } from "./config-parser"; import { SectionType } from "jalhyd"; export class FormulaireSection extends FormulaireFixedVar { @@ -16,17 +15,8 @@ export class FormulaireSection extends FormulaireFixedVar { */ private parseDefaultSectionType() { if (this._defaultSectionType === undefined) { - const jp = new ConfigParser(this._jsonConfig); - for (const fs of jp.forAll("fieldset")) { - const fsp = new ConfigParser(fs["fields"]); - for (const sel of fsp.forAll("select")) { - if (sel["id"] === "select_section") { - const st = sel["default"]; - this._defaultSectionType = SectionType[st]; - return; - } - } - } + const def = this.parseSelectDefaultValue(this._jsonConfig, "select_section"); + this._defaultSectionType = SectionType[def]; } }