cleanup(forms): cleanup
This commit is contained in:
parent
4d1ed509e3
commit
5ba5da5d25
modules
angular2/src/forms/directives
checkbox_value_accessor.tsdefault_value_accessor.tsng_control_name.tsng_form_control.tsng_form_model.tsng_model.tsselect_control_value_accessor.ts
examples/src/template_driven_forms
@ -30,12 +30,10 @@ import {setProperty} from './shared';
|
|||||||
})
|
})
|
||||||
export class CheckboxControlValueAccessor implements ControlValueAccessor {
|
export class CheckboxControlValueAccessor implements ControlValueAccessor {
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
onChange: Function;
|
onChange = (_) => {};
|
||||||
onTouched: Function;
|
onTouched = () => {};
|
||||||
|
|
||||||
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
|
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
|
||||||
this.onChange = (_) => {};
|
|
||||||
this.onTouched = (_) => {};
|
|
||||||
cd.valueAccessor = this;
|
cd.valueAccessor = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,12 +33,10 @@ import {setProperty} from './shared';
|
|||||||
})
|
})
|
||||||
export class DefaultValueAccessor implements ControlValueAccessor {
|
export class DefaultValueAccessor implements ControlValueAccessor {
|
||||||
value: string = null;
|
value: string = null;
|
||||||
onChange: Function;
|
onChange = (_) => {};
|
||||||
onTouched: Function;
|
onTouched = () => {};
|
||||||
|
|
||||||
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
|
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
|
||||||
this.onChange = (_) => {};
|
|
||||||
this.onTouched = (_) => {};
|
|
||||||
cd.valueAccessor = this;
|
cd.valueAccessor = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,25 +75,23 @@ const controlNameBinding =
|
|||||||
@Directive({
|
@Directive({
|
||||||
selector: '[ng-control]',
|
selector: '[ng-control]',
|
||||||
hostInjector: [controlNameBinding],
|
hostInjector: [controlNameBinding],
|
||||||
properties: ['name: ng-control', 'model: ng-model'],
|
properties: ['name: ngControl', 'model: ngModel'],
|
||||||
events: ['ngModel'],
|
events: ['update: ngModel'],
|
||||||
lifecycle: [onDestroy, onChange],
|
lifecycle: [onDestroy, onChange],
|
||||||
exportAs: 'form'
|
exportAs: 'form'
|
||||||
})
|
})
|
||||||
export class NgControlName extends NgControl {
|
export class NgControlName extends NgControl {
|
||||||
_parent: ControlContainer;
|
_parent: ControlContainer;
|
||||||
ngModel: EventEmitter;
|
update = new EventEmitter();
|
||||||
model: any;
|
model: any;
|
||||||
ngValidators: QueryList<NgValidator>;
|
ngValidators: QueryList<NgValidator>;
|
||||||
_added: boolean;
|
_added = false;
|
||||||
|
|
||||||
// Scope the query once https://github.com/angular/angular/issues/2603 is fixed
|
// Scope the query once https://github.com/angular/angular/issues/2603 is fixed
|
||||||
constructor(@Ancestor() parent: ControlContainer,
|
constructor(@Ancestor() parent: ControlContainer,
|
||||||
@Query(NgValidator) ngValidators: QueryList<NgValidator>) {
|
@Query(NgValidator) ngValidators: QueryList<NgValidator>) {
|
||||||
super();
|
super();
|
||||||
this._parent = parent;
|
this._parent = parent;
|
||||||
this.ngModel = new EventEmitter();
|
|
||||||
this._added = false;
|
|
||||||
this.ngValidators = ngValidators;
|
this.ngValidators = ngValidators;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +107,7 @@ export class NgControlName extends NgControl {
|
|||||||
|
|
||||||
onDestroy() { this.formDirective.removeControl(this); }
|
onDestroy() { this.formDirective.removeControl(this); }
|
||||||
|
|
||||||
viewToModelUpdate(newValue: any): void { ObservableWrapper.callNext(this.ngModel, newValue); }
|
viewToModelUpdate(newValue: any): void { ObservableWrapper.callNext(this.update, newValue); }
|
||||||
|
|
||||||
get path(): List<string> { return controlPath(this.name, this._parent); }
|
get path(): List<string> { return controlPath(this.name, this._parent); }
|
||||||
|
|
||||||
|
@ -63,23 +63,21 @@ const formControlBinding =
|
|||||||
@Directive({
|
@Directive({
|
||||||
selector: '[ng-form-control]',
|
selector: '[ng-form-control]',
|
||||||
hostInjector: [formControlBinding],
|
hostInjector: [formControlBinding],
|
||||||
properties: ['form: ng-form-control', 'model: ng-model'],
|
properties: ['form: ngFormControl', 'model: ngModel'],
|
||||||
events: ['ngModel'],
|
events: ['update: ngModel'],
|
||||||
lifecycle: [onChange],
|
lifecycle: [onChange],
|
||||||
exportAs: 'form'
|
exportAs: 'form'
|
||||||
})
|
})
|
||||||
export class NgFormControl extends NgControl {
|
export class NgFormControl extends NgControl {
|
||||||
form: Control;
|
form: Control;
|
||||||
ngModel: EventEmitter;
|
update = new EventEmitter();
|
||||||
_added: boolean;
|
_added = false;
|
||||||
model: any;
|
model: any;
|
||||||
ngValidators: QueryList<NgValidator>;
|
ngValidators: QueryList<NgValidator>;
|
||||||
|
|
||||||
// Scope the query once https://github.com/angular/angular/issues/2603 is fixed
|
// Scope the query once https://github.com/angular/angular/issues/2603 is fixed
|
||||||
constructor(@Query(NgValidator) ngValidators: QueryList<NgValidator>) {
|
constructor(@Query(NgValidator) ngValidators: QueryList<NgValidator>) {
|
||||||
super();
|
super();
|
||||||
this.ngModel = new EventEmitter();
|
|
||||||
this._added = false;
|
|
||||||
this.ngValidators = ngValidators;
|
this.ngValidators = ngValidators;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,5 +98,5 @@ export class NgFormControl extends NgControl {
|
|||||||
|
|
||||||
get validator(): Function { return composeNgValidator(this.ngValidators); }
|
get validator(): Function { return composeNgValidator(this.ngValidators); }
|
||||||
|
|
||||||
viewToModelUpdate(newValue: any): void { ObservableWrapper.callNext(this.ngModel, newValue); }
|
viewToModelUpdate(newValue: any): void { ObservableWrapper.callNext(this.update, newValue); }
|
||||||
}
|
}
|
||||||
|
@ -95,14 +95,9 @@ const formDirectiveBinding =
|
|||||||
})
|
})
|
||||||
export class NgFormModel extends ControlContainer implements Form {
|
export class NgFormModel extends ControlContainer implements Form {
|
||||||
form: ControlGroup = null;
|
form: ControlGroup = null;
|
||||||
directives: List<NgControl>;
|
directives: List<NgControl> = [];
|
||||||
ngSubmit = new EventEmitter();
|
ngSubmit = new EventEmitter();
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.directives = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
onChange(_) { this._updateDomValue(); }
|
onChange(_) { this._updateDomValue(); }
|
||||||
|
|
||||||
get formDirective(): Form { return this; }
|
get formDirective(): Form { return this; }
|
||||||
|
@ -33,15 +33,15 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe
|
|||||||
@Directive({
|
@Directive({
|
||||||
selector: '[ng-model]:not([ng-control]):not([ng-form-control])',
|
selector: '[ng-model]:not([ng-control]):not([ng-form-control])',
|
||||||
hostInjector: [formControlBinding],
|
hostInjector: [formControlBinding],
|
||||||
properties: ['model: ng-model'],
|
properties: ['model: ngModel'],
|
||||||
events: ['ngModel'],
|
events: ['update: ngModel'],
|
||||||
lifecycle: [onChange],
|
lifecycle: [onChange],
|
||||||
exportAs: 'form'
|
exportAs: 'form'
|
||||||
})
|
})
|
||||||
export class NgModel extends NgControl {
|
export class NgModel extends NgControl {
|
||||||
_control = new Control("");
|
_control = new Control("");
|
||||||
_added = false;
|
_added = false;
|
||||||
ngModel = new EventEmitter();
|
update = new EventEmitter();
|
||||||
model: any;
|
model: any;
|
||||||
ngValidators: QueryList<NgValidator>;
|
ngValidators: QueryList<NgValidator>;
|
||||||
|
|
||||||
@ -69,5 +69,5 @@ export class NgModel extends NgControl {
|
|||||||
|
|
||||||
get validator(): Function { return composeNgValidator(this.ngValidators); }
|
get validator(): Function { return composeNgValidator(this.ngValidators); }
|
||||||
|
|
||||||
viewToModelUpdate(newValue: any): void { ObservableWrapper.callNext(this.ngModel, newValue); }
|
viewToModelUpdate(newValue: any): void { ObservableWrapper.callNext(this.update, newValue); }
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,11 @@ export class NgSelectOption {
|
|||||||
})
|
})
|
||||||
export class SelectControlValueAccessor implements ControlValueAccessor {
|
export class SelectControlValueAccessor implements ControlValueAccessor {
|
||||||
value = '';
|
value = '';
|
||||||
onChange: Function;
|
onChange = (_) => {};
|
||||||
onTouched: Function;
|
onTouched = () => {};
|
||||||
|
|
||||||
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
|
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
|
||||||
@Query(NgSelectOption, {descendants: true}) query: QueryList<NgSelectOption>) {
|
@Query(NgSelectOption, {descendants: true}) query: QueryList<NgSelectOption>) {
|
||||||
this.onChange = (_) => {};
|
|
||||||
this.onTouched = (_) => {};
|
|
||||||
cd.valueAccessor = this;
|
cd.valueAccessor = this;
|
||||||
|
|
||||||
this._updateValueWhenListOfOptionsChanges(query);
|
this._updateValueWhenListOfOptionsChanges(query);
|
||||||
|
@ -35,9 +35,7 @@ class CheckoutModel {
|
|||||||
*/
|
*/
|
||||||
@Directive({selector: '[credit-card]'})
|
@Directive({selector: '[credit-card]'})
|
||||||
class CreditCardValidator {
|
class CreditCardValidator {
|
||||||
constructor(c: NgControl) {
|
get validator() { return CreditCardValidator.validate; }
|
||||||
c.validator = Validators.compose([c.validator, CreditCardValidator.validate]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static validate(c): StringMap<string, boolean> {
|
static validate(c): StringMap<string, boolean> {
|
||||||
if (isPresent(c.value) && RegExpWrapper.test(new RegExp("^\\d{16}$"), c.value)) {
|
if (isPresent(c.value) && RegExpWrapper.test(new RegExp("^\\d{16}$"), c.value)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user