0

I have a wizard with about a hundred form fields. These fields are prepopulated with factory settings using FormBuilder in the OnInit.

The user has also the option to upload a previously saved config using a JSON file. I can parse the file no problem, but obviously, if the user launches the wizard, the OnInit will overwrite it all. Short of having to maintain two wizards (with all it's validation methods etc.) how can I inject the JSON items into the wizard BEFORE the user launches it the first time? any ideas?

## EDIT ##

Here's the code for reading the file and using patchValue() to add the data to the form. I suppose that now I need to know before the onInit if parsedConfig was filled or not:

file:any;
fileChanged(e) {
this.file = e.target.files[0];
}

uploadConfig(file) {

  var fileReader = new FileReader();
  fileReader.onload = (e) => {
  var parsedConfig = JSON.parse(fileReader.result)

  this.datainputForm.patchValue ({
    company: parsedConfig.company
    // add another 99 fields here
  })
 }
 fileReader.readAsText(this.file);
}

(my first time posting here, this Editor is killing me :-/ )

4

0 に答える 0