Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { Injectable } from '@angular/core';
import {
Validators,
Control,
ControlGroup
} from '@angular/common';
import { ValidationHelper } from
'../../../../common/helpers/validation.helper';
@Injectable()
export class HnyShippingAddressFormBuilder {
public static buildForm(address?): ControlGroup {
if (!address) { address = {}; }
return new ControlGroup({
firstname: this.firstname(address.firstname),
lastname: this.lastname(address.lastname),
email: this.email(address.email),
telephone: this.telephone(address.telephone),
address1: this.address1(address.address1),
country_id: this.country_id(address.country_id),
city: this.city(address.city),
region: this.region(address.region),
postcode: this.postcode(address.postcode)
});
}
/**
* Inidividual values
*/
private static firstname(initValue?): Control {
return new Control(
initValue || '',
Validators.required
);
}
private static lastname(initValue?): Control {
return new Control(
initValue || '',
Validators.required
);
}
private static email(initValue?): Control {
return new Control(
initValue || '',
Validators.compose([
Validators.required,
ValidationHelper.emailValidator
])
);
}
private static telephone(initValue?): Control {
return new Control(
initValue || '',
Validators.compose([
Validators.required,
ValidationHelper.phoneValidator
])
);
}
private static address1(initValue?): Control {
return new Control(
initValue || '',
Validators.required
);
}
private static country_id(initValue?): Control {
return new Control(
initValue || '',
Validators.required
);
}
private static city(initValue?): Control {
return new Control(
initValue || '',
Validators.required
);
}
private static region(initValue?): Control {
return new Control(
initValue || '',
Validators.required
);
}
private static postcode(initValue?): Control {
return new Control(
initValue || '',
Validators.required
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.