expect(form.getValue('floating')).toBe(0.1);
});
- it('returns strings that are not empty', () => {
+ it('returns strings', () => {
+ expect(form.getValue('emptyString')).toBe('');
expect(form.getValue('someString1')).toBe('s');
expect(form.getValue('someString2')).toBe('sth');
});
expect(form.getValue('undefined')).toBe(null);
});
- it('returns a falsy value for empty string, null, undefined, false and 0', () => {
- expect(form.getValue('emptyString')).toBe(false);
+ it('returns a falsy value for null, undefined, false and 0', () => {
expect(form.getValue('false')).toBeFalsy();
expect(form.getValue('null')).toBeFalsy();
expect(form.getValue('number0')).toBeFalsy();
});
-
- it('test _filterValue', () => {
- expect(form._filterValue(0)).toBe(true);
- expect(form._filterValue(null)).toBe(true);
- expect(form._filterValue(false)).toBe(true);
- expect(form._filterValue('')).toBe(false);
- });
});
describe('should test showError', () => {
/**
* Get a control out of any control even if its nested in other CdFormGroups or a FormGroup
- *
- * @param {string} controlName
- * @returns {AbstractControl}
*/
get(controlName: string): AbstractControl {
const control = this._get(controlName);
}
/**
- * Get the value of a control if it has none it will return false
- *
- * @param {string} controlName
- * @returns {any} false or the value of the control
+ * Get the value of a control
*/
getValue(controlName: string): any {
- const value = this.get(controlName).value;
- return this._filterValue(value) && value;
- }
-
- // Overwrite this if needed.
- _filterValue(value) {
- return value !== '';
+ return this.get(controlName).value;
}
/**
*
* Very useful if a function is called through a value changes event but the value
* should be changed within the call.
- *
- * @param {string} controlName
- * @param value
*/
silentSet(controlName: string, value: any) {
this.get(controlName).setValue(value, { emitEvent: false });
/**
* Indicates errors of the control in templates
- *
- * @param {string} controlName
- * @param {NgForm} form
- * @param {string} errorName
- * @returns {boolean}
*/
- showError(controlName: string, form: NgForm, errorName?: string) {
+ showError(controlName: string, form: NgForm, errorName?: string): boolean {
const control = this.get(controlName);
return (
(form.submitted || control.dirty) &&