Skip to content
Snippets Groups Projects
Commit e0403b11 authored by François Grand's avatar François Grand
Browse files

fix: standard select defaut value from calculator configuration not honored

refs #483
parent d816e82b
No related branches found
No related tags found
2 merge requests!225Release v4.17.0,!176Resolve "Fusionner les "select" avec "source" et les "select_custom""
...@@ -4,7 +4,7 @@ import { ...@@ -4,7 +4,7 @@ import {
Props, Props,
Observer, Observer,
Nub, Nub,
Session, enumValueFromString
} from "jalhyd"; } from "jalhyd";
import { FormulaireElement } from "./formulaire-element"; import { FormulaireElement } from "./formulaire-element";
...@@ -295,13 +295,7 @@ export class FieldSet extends FormulaireElement implements Observer { ...@@ -295,13 +295,7 @@ export class FieldSet extends FormulaireElement implements Observer {
// Sets Nub default property, unless this property is already set // Sets Nub default property, unless this property is already set
const currentValue = this.properties.getPropValue(prop); const currentValue = this.properties.getPropValue(prop);
if (defaultValue !== undefined && currentValue === undefined) { if (defaultValue !== undefined && currentValue === undefined) {
let formalValue = defaultValue; this.setNubPropValue(prop, enumValueFromString(prop, defaultValue));
// !! property names must be unique throughout JaLHyd !!
const enumClass = Session.enumFromProperty[prop];
if (enumClass) {
formalValue = enumClass[defaultValue];
}
this.setNubPropValue(prop, formalValue);
} }
} }
} }
......
...@@ -4,7 +4,7 @@ import { arraysAreEqual } from "../../../util"; ...@@ -4,7 +4,7 @@ import { arraysAreEqual } from "../../../util";
import { FormulaireNode } from "../formulaire-node"; import { FormulaireNode } from "../formulaire-node";
import { ServiceFactory } from "app/services/service-factory"; import { ServiceFactory } from "app/services/service-factory";
import { FormulaireDefinition } from "../../definition/form-definition"; import { FormulaireDefinition } from "../../definition/form-definition";
import { Nub } from "jalhyd"; import { enumValueFromString, Nub } from "jalhyd";
export abstract class SelectField extends Field { export abstract class SelectField extends Field {
...@@ -128,10 +128,16 @@ export abstract class SelectField extends Field { ...@@ -128,10 +128,16 @@ export abstract class SelectField extends Field {
protected findAndSetDefaultValue() { protected findAndSetDefaultValue() {
// default to first available entry if any // default to first available entry if any
if (this._entries.length > 0) { if (this._entries.length > 0) {
let val;
if (this._configDefaultValue === undefined) {
val = this._entries[0];
} else {
val = this.getEntryFromValue(enumValueFromString(this._associatedProperty, this._configDefaultValue));
}
if (this._multiple) { if (this._multiple) {
this.setValue([this._entries[0]]); this.setValue([val]);
} else { } else {
this.setValue(this._entries[0]); this.setValue(val);
} }
} else { } else {
// notify observers that no value is selected anymore // notify observers that no value is selected anymore
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment