Skip to content

Commit

Permalink
file input bug fixed (closes #304) and NoImplicitAny TS errors fixed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
udos86 committed Apr 29, 2017
1 parent cf866bb commit 84e3180
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 46 deletions.
50 changes: 37 additions & 13 deletions modules/core/src/component/dynamic-form-control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ export abstract class DynamicFormControlComponent implements OnInit, AfterViewIn

get errorMessages(): string[] {

let messages = [];
let model = this.model as DynamicFormValueControlModel<DynamicFormControlValue>,
messages = [];

if (isDefined(this.model["errorMessages"])) {
if (isDefined(model.errorMessages)) {

for (let validatorName in this.control.errors) {

Expand All @@ -112,21 +113,21 @@ export abstract class DynamicFormControlComponent implements OnInit, AfterViewIn
validatorName = validatorName.replace("length", "Length");
}

if (this.model["errorMessages"][validatorName]) {
if (model.errorMessages[validatorName]) {

message = this.model["errorMessages"][validatorName].replace(/\{\{(.+?)\}\}/mg,
message = model.errorMessages[validatorName].replace(/\{\{(.+?)\}\}/mg,
(match: string, expression: string) => {

let propertySource = this.model,
propertyName = expression;
let propertySource: any = model,
propertyName: string = expression;

if (expression.indexOf("validator.") >= 0) {

propertySource = this.control.errors[validatorName];
propertySource = this.control.errors[validatorName] as any;
propertyName = expression.replace("validator.", "");
}

return propertySource[propertyName] ? propertySource[propertyName] : null;
return propertySource[propertyName] as string ? propertySource[propertyName] : null;
});

} else {
Expand Down Expand Up @@ -266,7 +267,7 @@ export abstract class DynamicFormControlComponent implements OnInit, AfterViewIn
value ? this.control.disable() : this.control.enable();
}

onValueChange($event: Event | DynamicFormControlEvent | any): void {
onValueChange($event: Event | DynamicFormControlEvent | any): void {

if ($event instanceof Event) { // native HTML5 change event

Expand All @@ -277,7 +278,10 @@ export abstract class DynamicFormControlComponent implements OnInit, AfterViewIn
let model = this.model as DynamicInputModel;

if (model.inputType === DYNAMIC_FORM_CONTROL_INPUT_TYPE_FILE) {
model.files = $event.srcElement["files"];

let inputElement: any = ($event as Event).target || ($event as Event).srcElement;

model.files = inputElement.files as FileList;
}
}

Expand All @@ -295,17 +299,37 @@ export abstract class DynamicFormControlComponent implements OnInit, AfterViewIn

onFocusChange($event: FocusEvent | DynamicFormControlEvent): void {

let emitValue;

if ($event instanceof FocusEvent) {

$event.stopPropagation();

this.hasFocus = $event.type === "focus";
emitValue = {$event: $event, control: this.control, model: this.model};

if ($event.type === "focus") {

this.hasFocus = true;
this.focus.emit(emitValue);

} else {

this[$event.type].emit({$event: $event, control: this.control, model: this.model});
this.hasFocus = false;
this.blur.emit(emitValue);
}

} else {

this[(($event as DynamicFormControlEvent).$event as FocusEvent).type].emit($event);
emitValue = $event as DynamicFormControlEvent;

if ((emitValue.$event as FocusEvent).type === "focus") {

this.focus.emit(emitValue);

} else {

this.blur.emit(emitValue);
}
}
}
}
13 changes: 7 additions & 6 deletions modules/core/src/service/dynamic-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class DynamicFormService {

getValidatorFn(validatorName: string, validatorArgs?: any): ValidatorFn | never {

let validatorFn: any = Validators[validatorName] || this.getCustomValidatorFn(validatorName);
let validatorFn: Function | null = (Validators as any)[validatorName] || this.getCustomValidatorFn(validatorName);

if (!isFunction(validatorFn)) {
throw new Error(`validator "${validatorName}" is not provided via NG_VALIDATORS`);
Expand All @@ -98,7 +98,8 @@ export class DynamicFormService {

getAsyncValidatorFn(asyncValidatorName: string, asyncValidatorArgs?: any): AsyncValidatorFn | never {

let asyncValidatorFn: any = Validators[asyncValidatorName] || this.getCustomAsyncValidatorFn(asyncValidatorName);

let asyncValidatorFn: Function | null = (Validators as any)[asyncValidatorName] || this.getCustomAsyncValidatorFn(asyncValidatorName);

if (!isFunction(asyncValidatorFn)) {
throw new Error(`async validator "${asyncValidatorName}" is not provided via NG_ASYNC_VALIDATORS`);
Expand Down Expand Up @@ -269,21 +270,21 @@ export class DynamicFormService {

if ((index >= 0 && index < model.size) && (newIndex >= 0 && newIndex < model.size)) {

let moving = [];
let movingGroups: AbstractControl[] = [];

for (let i = moveUp ? index : newIndex; i <= (moveUp ? newIndex : index); i++) {
moving.push(formArray.at(i));
movingGroups.push(formArray.at(i));
}

moving.forEach((formControl, idx) => {
movingGroups.forEach((formControl, idx) => {

let position;

if (moveUp) {
position = idx === 0 ? newIndex : index + idx - 1;

} else {
position = idx === moving.length - 1 ? newIndex : newIndex + idx + 1;
position = idx === movingGroups.length - 1 ? newIndex : newIndex + idx + 1;
}

formArray.setControl(position, formControl);
Expand Down
8 changes: 4 additions & 4 deletions modules/ui-kendo/src/dynamic-form-kendo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class DynamicFormKendoComponent extends DynamicFormControlComponent {

protected setKendoTemplateDirective(directive: DynamicTemplateDirective): void {

let templateDirectives: object,
let templateDirectives: any,
viewChild: any;

if (this.kendoAutoComplete) {
Expand Down Expand Up @@ -122,7 +122,7 @@ export class DynamicFormKendoComponent extends DynamicFormControlComponent {
viewChild = this.kendoUpload;
}

Object.keys(templateDirectives || {}).forEach((key: string) => {
Object.keys(templateDirectives || ({} as any)).forEach((key: string) => {

if (templateDirectives[key] === directive.type) {
viewChild[key] = directive;
Expand Down Expand Up @@ -207,11 +207,11 @@ export class DynamicFormKendoComponent extends DynamicFormControlComponent {
.forEach(directive => this.setKendoTemplateDirective(directive));
}

onFocus($event): void {
onFocus($event: null): void {
this.focus.emit({$event: $event, control: this.control, model: this.model});
}

onBlur($event): void {
onBlur($event: null): void {
this.blur.emit({$event: $event, control: this.control, model: this.model});
}
}
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@
},
"homepage": "https://github.com/udos86/ng2-dynamic-forms#readme",
"dependencies": {
"@angular/animations": "^4.0.3",
"@angular/common": "^4.0.3",
"@angular/compiler": "^4.0.3",
"@angular/animations": "^4.1.0",
"@angular/common": "^4.1.0",
"@angular/compiler": "^4.1.0",
"@angular/compiler-cli": "^4.0.2",
"@angular/core": "^4.0.3",
"@angular/forms": "^4.0.3",
"@angular/http": "^4.0.3",
"@angular/core": "^4.1.0",
"@angular/forms": "^4.1.0",
"@angular/http": "^4.1.0",
"@angular/material": "^2.0.0-beta.3",
"@angular/platform-browser": "^4.0.3",
"@angular/platform-browser-dynamic": "^4.0.3",
"@angular/router": "^4.0.3",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.23",
"@angular/platform-browser": "^4.1.0",
"@angular/platform-browser-dynamic": "^4.1.0",
"@angular/router": "^4.1.0",
"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.25",
"@ng2-dynamic-forms/core": "^1.4.6",
"@ng2-dynamic-forms/ui-basic": "^1.4.6",
"@ng2-dynamic-forms/ui-bootstrap": "^1.4.6",
Expand All @@ -61,19 +61,19 @@
"gulp-sourcemaps": "^2.6.0",
"hammerjs": "^2.0.8",
"ionic-angular": "^3.0.1",
"primeng": "^4.0.0-rc.3",
"primeng": "^4.0.0-rc.4",
"quill": "^1.2.4",
"rxjs": "^5.3.0",
"tslint": "^5.1.0",
"typescript": "^2.3.0",
"zone.js": "^0.8.8"
"zone.js": "^0.8.9"
},
"devDependencies": {
"@angular/compiler-cli": "^4.0.3",
"@angular/compiler-cli": "^4.1.0",
"@types/hammerjs": "^2.0.34",
"@types/jasmine": "^2.5.47",
"@types/node": "^7.0.13",
"codelyzer": "^3.0.0",
"@types/node": "^7.0.14",
"codelyzer": "^3.0.1",
"dateformat": "^2.0.0",
"del": "^2.2.2",
"gulp": "^3.9.1",
Expand All @@ -88,7 +88,7 @@
"gulp-typescript": "^3.1.6",
"gulp-util": "^3.0.8",
"html-minifier": "^3.4.3",
"jasmine-core": "^2.5.2",
"jasmine-core": "^2.6.1",
"jasmine-spec-reporter": "^4.0.0",
"karma": "^1.6.0",
"karma-chrome-launcher": "^2.0.0",
Expand All @@ -108,19 +108,19 @@
"systemjs": "^0.20.12",
"systemjs-builder": "^0.16.4",
"tslint": "^5.0.0",
"typedoc": "^0.5.10",
"typescript": ">2.2.2",
"typedoc": "^0.6.0",
"typescript": "^2.3.2",
"webpack": "^2.4.1"
},
"optionalDependencies": {
"@progress/kendo-angular-dateinputs": "^0.8.1",
"@progress/kendo-angular-dropdowns": "^0.39.3",
"@progress/kendo-angular-inputs": "^0.23.3",
"@progress/kendo-angular-dateinputs": "^0.8.3",
"@progress/kendo-angular-dropdowns": "^0.39.6",
"@progress/kendo-angular-inputs": "^0.23.4",
"@progress/kendo-angular-intl": "^0.12.0",
"@progress/kendo-angular-l10n": "^0.3.0",
"@progress/kendo-angular-resize-sensor": "^0.11.0",
"@progress/kendo-angular-upload": "^0.20.0",
"@progress/kendo-date-math": "^0.4.0",
"@progress/kendo-theme-default": "^2.31.3"
"@progress/kendo-theme-default": "^2.31.7"
}
}
2 changes: 1 addition & 1 deletion tsconfig.es5.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"noImplicitAny": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
Expand Down

0 comments on commit 84e3180

Please sign in to comment.