MOBILE-4470 database: Don't display values that are no longer valid
parent
b7beaead0c
commit
1c6551a6e0
|
@ -17,4 +17,4 @@
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<core-format-text *ngIf="displayMode && value && value.content" [text]="value.content" [filter]="false" />
|
<core-format-text *ngIf="displayMode && content" [text]="content" [filter]="false" />
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { AddonModDataFieldPluginBaseComponent } from '../../../classes/base-fiel
|
||||||
})
|
})
|
||||||
export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginBaseComponent {
|
export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginBaseComponent {
|
||||||
|
|
||||||
|
content?: string;
|
||||||
options: {
|
options: {
|
||||||
key: string;
|
key: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
@ -40,31 +41,32 @@ export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginB
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options = this.field.param1.split(/\r?\n/).map((option) => ({ key: option, value: option }));
|
|
||||||
|
|
||||||
const values: string[] = [];
|
|
||||||
if (this.editMode && this.value && this.value.content) {
|
|
||||||
this.value.content.split('##').forEach((value) => {
|
|
||||||
const x = this.options.findIndex((option) => value == option.key);
|
|
||||||
if (x >= 0) {
|
|
||||||
values.push(value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.searchMode) {
|
if (this.searchMode) {
|
||||||
this.addControl('f_' + this.field.id + '_allreq');
|
this.addControl('f_' + this.field.id + '_allreq');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addControl('f_' + this.field.id, values);
|
this.addControl('f_' + this.field.id, this.getValidValues(this.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
protected updateValue(value?: Partial<AddonModDataEntryField>): void {
|
protected updateValue(value?: Partial<AddonModDataEntryField>): void {
|
||||||
this.value = value || {};
|
super.updateValue(value);
|
||||||
this.value.content = value?.content?.split('##').join('<br>');
|
|
||||||
|
this.content = this.getValidValues(value).join('<br>');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of valid values from current field value.
|
||||||
|
*
|
||||||
|
* @param value Field value.
|
||||||
|
* @returns List of valid values.
|
||||||
|
*/
|
||||||
|
protected getValidValues(value?: Partial<AddonModDataEntryField>): string[] {
|
||||||
|
this.options = this.field.param1.split(/\r?\n/).map((option) => ({ key: option, value: option }));
|
||||||
|
|
||||||
|
return value?.content?.split('##').filter((value) => this.options.some(option => value === option.key)) ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,4 @@
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<core-format-text *ngIf="displayMode && value && value.content" [text]="value.content" [filter]="false" />
|
<core-format-text *ngIf="displayMode && content" [text]="content" [filter]="false" />
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { AddonModDataFieldPluginBaseComponent } from '../../../classes/base-fiel
|
||||||
})
|
})
|
||||||
export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPluginBaseComponent {
|
export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPluginBaseComponent {
|
||||||
|
|
||||||
|
content?: string;
|
||||||
options: {
|
options: {
|
||||||
key: string;
|
key: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
@ -40,31 +41,32 @@ export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPlugin
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options = this.field.param1.split(/\r?\n/).map((option) => ({ key: option, value: option }));
|
|
||||||
|
|
||||||
const values: string[] = [];
|
|
||||||
if (this.editMode && this.value?.content) {
|
|
||||||
this.value.content.split('##').forEach((value) => {
|
|
||||||
const x = this.options.findIndex((option) => value == option.key);
|
|
||||||
if (x >= 0) {
|
|
||||||
values.push(value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.searchMode) {
|
if (this.searchMode) {
|
||||||
this.addControl('f_' + this.field.id + '_allreq');
|
this.addControl('f_' + this.field.id + '_allreq');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addControl('f_' + this.field.id, values);
|
this.addControl('f_' + this.field.id, this.getValidValues(this.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
protected updateValue(value?: Partial<AddonModDataEntryField>): void {
|
protected updateValue(value?: Partial<AddonModDataEntryField>): void {
|
||||||
this.value = value || {};
|
super.updateValue(value);
|
||||||
this.value.content = value?.content && value.content.split('##').join('<br>');
|
|
||||||
|
this.content = this.getValidValues(value).join('<br>');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of valid values from current field value.
|
||||||
|
*
|
||||||
|
* @param value Field value.
|
||||||
|
* @returns List of valid values.
|
||||||
|
*/
|
||||||
|
protected getValidValues(value?: Partial<AddonModDataEntryField>): string[] {
|
||||||
|
this.options = this.field.param1.split(/\r?\n/).map((option) => ({ key: option, value: option }));
|
||||||
|
|
||||||
|
return value?.content?.split('##').filter((value) => this.options.some(option => value === option.key)) ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue