mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2255] fixed loading for form loading data (#3032)
* [ADF-2255] fixed loading for form loading data * [ADF-2255] fix wrong placeholder * [ADF-2255] fixed and added test for new value retrieving form * [ADF-2255] fixed test on validation
This commit is contained in:
@@ -82,9 +82,9 @@ describe('FormFieldValidator', () => {
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
required: true,
|
||||
value: 'one',
|
||||
options: [{ id: 'two', name: 'two' }]
|
||||
});
|
||||
field.value = 'one';
|
||||
|
||||
expect(validator.validate(field)).toBeFalsy();
|
||||
});
|
||||
|
@@ -266,8 +266,8 @@ describe('FormFieldModel', () => {
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
options: [
|
||||
{id: 'opt1', value: 'Option 1'},
|
||||
{id: 'opt2', value: 'Option 2'}
|
||||
{id: 'opt1', name: 'Option 1'},
|
||||
{id: 'opt2', name: 'Option 2'}
|
||||
],
|
||||
value: 'opt2'
|
||||
});
|
||||
@@ -319,8 +319,8 @@ describe('FormFieldModel', () => {
|
||||
id: 'radio-1',
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
options: [
|
||||
{id: 'opt1', value: 'Option 1'},
|
||||
{id: 'opt2', value: 'Option 2'}
|
||||
{id: 'opt1', name: 'Option 1'},
|
||||
{id: 'opt2', name: 'Option 2'}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -334,8 +334,8 @@ describe('FormFieldModel', () => {
|
||||
id: 'radio-2',
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
options: [
|
||||
{id: 'opt1', value: 'Option 1'},
|
||||
{id: 'opt2', value: 'Option 2'}
|
||||
{id: 'opt1', name: 'Option 1'},
|
||||
{id: 'opt2', name: 'Option 2'}
|
||||
]
|
||||
});
|
||||
|
||||
|
@@ -298,6 +298,8 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
let emptyOption = json.options[0];
|
||||
if (value === '' || value === emptyOption.id || value === emptyOption.name) {
|
||||
value = emptyOption.id;
|
||||
} else if (value.id && value.name) {
|
||||
value = value.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,9 +313,12 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
// Activiti has a bug with default radio button value where initial selection passed as `name` value
|
||||
// so try resolving current one with a fallback to first entry via name or id
|
||||
// TODO: needs to be reported and fixed at Activiti side
|
||||
let entry: FormFieldOption[] = this.options.filter(opt => opt.id === value || opt.name === value);
|
||||
let entry: FormFieldOption[] = this.options.filter(opt =>
|
||||
opt.id === value || opt.name === value || (value && (opt.id === value.id || opt.name === value.name)));
|
||||
if (entry.length > 0) {
|
||||
value = entry[0].id;
|
||||
} else {
|
||||
value = this.options[0] ? this.options[0].id : json.value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,7 +381,7 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
}
|
||||
break;
|
||||
case FormFieldTypes.TYPEAHEAD:
|
||||
let taEntry: FormFieldOption[] = this.options.filter(opt => opt.id === this.value);
|
||||
let taEntry: FormFieldOption[] = this.options.filter(opt => opt.id === this.value || opt.name === this.value);
|
||||
if (taEntry.length > 0) {
|
||||
this.form.values[this.id] = taEntry[0];
|
||||
} else if (this.options.length > 0) {
|
||||
|
@@ -268,10 +268,6 @@ export class FormModel {
|
||||
if (data[field.id]) {
|
||||
field.json.value = data[field.id];
|
||||
field.value = field.parseValue(field.json);
|
||||
if (field.type === FormFieldTypes.DROPDOWN ||
|
||||
field.type === FormFieldTypes.RADIO_BUTTONS) {
|
||||
field.value = data[field.id].id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit
|
||||
|
||||
let fieldValue = this.field.value;
|
||||
if (fieldValue) {
|
||||
let toSelect = options.find(item => item.id === fieldValue);
|
||||
let toSelect = options.find(item => item.id === fieldValue || item.name.toLocaleLowerCase() === fieldValue.toLocaleLowerCase());
|
||||
if (toSelect) {
|
||||
this.value = toSelect.name;
|
||||
}
|
||||
|
Reference in New Issue
Block a user