[ADF-1951] fixed parsing date value when on readonly mode (#2674)

This commit is contained in:
Vito 2017-11-20 20:38:13 +00:00 committed by Eugenio Romano
parent f693a241a6
commit b35b8b0e2e
2 changed files with 33 additions and 1 deletions

View File

@ -224,6 +224,31 @@ describe('FormFieldModel', () => {
expect(form.values['ddmmyyy']).toEqual('2017-04-28T00:00:00.000Z');
});
it('should parse the date with the format DD-MM-YYYY when it is readonly', () => {
let form = new FormModel();
let field = new FormFieldModel(form, {
fieldType: 'FormFieldRepresentation',
id: 'ddmmyyy',
name: 'DD-MM-YYYY',
type: 'readonly',
value: '2017-04-28T00:00:00.000+0000',
required: false,
readOnly: true,
params: {
field: {
id: 'ddmmyyy',
name: 'DD-MM-YYYY',
type: 'date',
value: null,
required: false,
readOnly: false
}
},
dateDisplayFormat: 'DD-MM-YYYY'
});
expect(field.value).toBe('28-04-2017');
});
it('should return the label of selected dropdown value ', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN,

View File

@ -311,7 +311,7 @@ export class FormFieldModel extends FormWidgetModel {
This is needed due to Activiti displaying/editing dates in d-M-YYYY format
but storing on server in ISO8601 format (i.e. 2013-02-04T22:44:30.652Z)
*/
if (json.type === FormFieldTypes.DATE) {
if (this.isDateField(json)) {
if (value) {
let dateValue;
if (NumberFieldValidator.isNumber(value)) {
@ -417,4 +417,11 @@ export class FormFieldModel extends FormWidgetModel {
hasOptions() {
return this.options && this.options.length > 0;
}
private isDateField(json: any) {
return (json.params &&
json.params.field &&
json.params.field.type === FormFieldTypes.DATE ) ||
json.type === FormFieldTypes.DATE;
}
}