mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
16 changed files with 111 additions and 105 deletions
@ -1,26 +0,0 @@ |
|||||
/* |
|
||||
* Squidex Headless CMS |
|
||||
* |
|
||||
* @license |
|
||||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
||||
*/ |
|
||||
|
|
||||
import { StringFormControl } from './string-form-control'; |
|
||||
|
|
||||
describe('StringFormControl', () => { |
|
||||
it('should convert empty string to undefined', () => { |
|
||||
const formControl = new StringFormControl(); |
|
||||
|
|
||||
formControl.setValue(''); |
|
||||
|
|
||||
expect(formControl.value).toBeUndefined(); |
|
||||
}); |
|
||||
|
|
||||
it('should convert empty string to undefined when patching', () => { |
|
||||
const formControl = new StringFormControl(); |
|
||||
|
|
||||
formControl.patchValue(''); |
|
||||
|
|
||||
expect(formControl.value).toBeUndefined(); |
|
||||
}); |
|
||||
}); |
|
||||
@ -1,39 +0,0 @@ |
|||||
/* |
|
||||
* Squidex Headless CMS |
|
||||
* |
|
||||
* @license |
|
||||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
||||
*/ |
|
||||
|
|
||||
// tslint:disable: readonly-array
|
|
||||
|
|
||||
import { AbstractControlOptions, AsyncValidatorFn, FormControl, ValidatorFn } from '@angular/forms'; |
|
||||
|
|
||||
export type ValueOptions = { |
|
||||
onlySelf?: boolean; |
|
||||
emitEvent?: boolean; |
|
||||
emitModelToViewChange?: boolean; |
|
||||
emitViewToModelChange?: boolean; |
|
||||
}; |
|
||||
|
|
||||
export class StringFormControl extends FormControl { |
|
||||
constructor(formState?: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null) { |
|
||||
super(formState, validatorOrOpts, asyncValidator); |
|
||||
} |
|
||||
|
|
||||
public setValue(value: any, options?: ValueOptions) { |
|
||||
if (value === '') { |
|
||||
value = undefined; |
|
||||
} |
|
||||
|
|
||||
super.setValue(value, options); |
|
||||
} |
|
||||
|
|
||||
public patchValue(value: any, options?: ValueOptions) { |
|
||||
if (value === '') { |
|
||||
value = undefined; |
|
||||
} |
|
||||
|
|
||||
super.patchValue(value, options); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue