0

I've got following code that initialize form in my component:

let editMode: boolean = !!this.template.templateId;

this.editTemplateForm = this.formBuilder.group({
  templateId: {value: editMode ? this.template.templateId : '', validators: [Validators.required, this.templateIdValidator]},
  dataStorageTime: {value: editMode ? this.template.dataStorageTime : this.globalParameter.dataStorageTime, Validators.required, Validators.pattern("[0-9]+")]});

Value of variable this.template.templateId is undefined, so editMode is false. For dataStorageTime correct default value is set in linked input in form. Hovewer, for templateId input is set to "[object Object]" instead of empty string.

I'm using angular2 final realease.

1 Answer 1

2

This is the solution to my problem:

this.editTemplateForm = this.formBuilder.group({
templateId: [editMode ? this.template.templateId : '', [Validators.required, this.templateIdValidator]],
dataStorageTime: [editMode ? this.template.dataStorageTime : this.globalParameter.dataStorageTime, [Validators.required, Validators.pattern("[0-9]+")]]
});
Sign up to request clarification or add additional context in comments.

1 Comment

Upped your answer @mdziob, I've been banging my head for the regex pattern and tried a bunch of things, but never tried adding + in the pattern! Now my code works :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.