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

fix: modify SelectField.findAndSetDefaultValue() to use nub value for associated property

refs #592
parent 5894ee91
No related branches found
No related tags found
2 merge requests!225Release v4.17.0,!199Resolve "Incohérence dans les fichiers de session"
......@@ -132,22 +132,37 @@ export abstract class SelectField extends Field {
}
/**
* try to find a default value to select
* Try to find a default value to select.
* Priority order :
* - passed parameter
* - nub value for associated property
* - default value from configuration file
* - first select entry
*/
protected findAndSetDefaultValue(value?: string) {
// default to first available entry if any
if (this._entries.length > 0) {
let val: SelectEntry;
if (value !== undefined) {
val = this.getEntryFromValue(enumValueFromString(this._associatedProperty, value));
} else if (this._configDefaultValue === undefined) {
val = this._entries[0];
} else {
if (val === undefined) {
throw Error("invalid select default value " + value + " for " + this._associatedProperty + " property");
}
} else if (this.nub !== undefined) {
val = this.getEntryFromValue(this.nub.getPropValue(this._associatedProperty));
if (val === undefined) {
throw Error("invalid select default value for " + this._associatedProperty + " property");
}
} else if (this._configDefaultValue !== undefined) {
val = this.getEntryFromValue(enumValueFromString(this._associatedProperty, this._configDefaultValue));
if (val === undefined) {
throw Error("invalid select default value " + this._configDefaultValue + " for " + this._associatedProperty + " property");
}
} else {
val = this._entries[0];
}
if (this._multiple) {
this.setValue([val]);
} else {
......
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