16
modules/angular2/src/forms/form_builder.js
vendored
16
modules/angular2/src/forms/form_builder.js
vendored
@ -1,26 +1,26 @@
|
||||
import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {ControlGroup, Control, OptionalControl, OptionalControlGroup} from 'angular2/forms';
|
||||
import * as modelModule from './model';
|
||||
|
||||
|
||||
export class FormBuilder {
|
||||
group(controlsConfig, extra = null):ControlGroup {
|
||||
group(controlsConfig, extra = null):modelModule.ControlGroup {
|
||||
var controls = this._reduceControls(controlsConfig);
|
||||
var optionals = isPresent(extra) ? StringMapWrapper.get(extra, "optionals") : null;
|
||||
var validator = isPresent(extra) ? StringMapWrapper.get(extra, "validator") : null;
|
||||
|
||||
if (isPresent(validator)) {
|
||||
return new ControlGroup(controls, optionals, validator);
|
||||
return new modelModule.ControlGroup(controls, optionals, validator);
|
||||
} else {
|
||||
return new ControlGroup(controls, optionals);
|
||||
return new modelModule.ControlGroup(controls, optionals);
|
||||
}
|
||||
}
|
||||
|
||||
control(value, validator:Function = null):Control {
|
||||
control(value, validator:Function = null):modelModule.Control {
|
||||
if (isPresent(validator)) {
|
||||
return new Control(value, validator);
|
||||
return new modelModule.Control(value, validator);
|
||||
} else {
|
||||
return new Control(value);
|
||||
return new modelModule.Control(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ export class FormBuilder {
|
||||
}
|
||||
|
||||
_createControl(controlConfig) {
|
||||
if (controlConfig instanceof Control || controlConfig instanceof ControlGroup) {
|
||||
if (controlConfig instanceof modelModule.Control || controlConfig instanceof modelModule.ControlGroup) {
|
||||
return controlConfig;
|
||||
|
||||
} else if (ListWrapper.isList(controlConfig)) {
|
||||
|
10
modules/angular2/src/forms/validators.js
vendored
10
modules/angular2/src/forms/validators.js
vendored
@ -1,18 +1,18 @@
|
||||
import {isBlank, isPresent} from 'angular2/src/facade/lang';
|
||||
import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {ControlGroup, Control} from 'angular2/forms';
|
||||
import * as modelModule from './model';
|
||||
|
||||
export function required(c:Control) {
|
||||
export function required(c:modelModule.Control) {
|
||||
return isBlank(c.value) || c.value == "" ? {"required" : true} : null;
|
||||
}
|
||||
|
||||
export function nullValidator(c:Control) {
|
||||
export function nullValidator(c:modelModule.Control) {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function compose(validators:List<Function>):Function {
|
||||
return function(c:Control) {
|
||||
return function(c:modelModule.Control) {
|
||||
var res = ListWrapper.reduce(validators, (res, validator) => {
|
||||
var errors = validator(c);
|
||||
return isPresent(errors) ? StringMapWrapper.merge(res, errors) : res;
|
||||
@ -21,7 +21,7 @@ export function compose(validators:List<Function>):Function {
|
||||
}
|
||||
}
|
||||
|
||||
export function controlGroupValidator(c:ControlGroup) {
|
||||
export function controlGroupValidator(c:modelModule.ControlGroup) {
|
||||
var res = {};
|
||||
StringMapWrapper.forEach(c.controls, (control, name) => {
|
||||
if (c.contains(name) && isPresent(control.errors)) {
|
||||
|
Reference in New Issue
Block a user