How to edit a form, with a typescript response?

0

I have the fake form (Because I'm missing the call from the api), and I would like to leave everything ready to be able to edit it with an entity. On the same page: when pressing a button.

this.fakeResponse = {
  name: 'Juan',
  lastName: 'Antonio',
  gender: 'Male',
  dateBirth: 'September 20, 1999',
  nationality: 'Spain',
  documentId: 'AB125315',
  documentExpiryDate: 'December 29, 2025',
  documentIssueDate: 'December 29, 2015',
  placeBirth: 'September 15 2012',
  address: {
    street_name: 'Calle Jaime 1',
    city: 'Sueras',
    province: 'Castellon',
    postcode: '12223',
    country: 'Spain',
  },
  nationalDocumentation: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Bahamas_sticker_visitors_visa_2014.png/1200px-Bahamas_sticker_visitors_visa_2014.png',
  proofOfResidence: 'http://hunecompany.com/wp-content/uploads/2018/02/proof-of-residency-letter-notarized-customer-care-award-certificate-template.jpg',
  selfie: 'http://i2.wp.com/www.where2wander.com/wp-content/uploads/2016/04/Top-10-Must-Dos-Bahamas-3.jpg?resize=830%2C556',
  auditorStatus: 'Closed',
  date: 'January 2, 2018',
  auditor: 'A123',
  consumerStatus: 'Closed',
  email: '[email protected]',
  kyc: 'level2',
  balance: '20€',
  phone: '680444605'
};



 private initRegisterForm() {
    this.registerFormErrors = {
      name: {},
      lastName: {},
      gender: {},
      dateBirth: {},
      nationality: {},
      documentId: {},
      documentExpiryDate: {},
      documentIssueDate: {},
      placeBirth: {},
      addressStreet: {},
      addressCity: {},
      addressIslandName: {},
      addressPostcode: {},
      nationalDocumentation: {},
      proofOfResidence: {},
      selfie: {},
      date: {},
      auditor: {},
      consumerName: {}
    }

this.registerForm = this.formBuilder.group({
  name: ['', Validators.required],
  lastName: ['', Validators.required],
  gender: ['', Validators.required],
  dateBirth: ['', Validators.required],
  nationality: ['', Validators.required],
  documentId: ['', Validators.required],
  documentExpiryDate: ['', Validators.required],
  documentIssueDate: ['', Validators.required],
  placeBirth: ['', Validators.required],
  addressStreet: ['', Validators.required],
  addressCity: ['', Validators.required],
  addressIslandName: ['', Validators.required],
  addressPostcode: ['', Validators.required],
  nationalDocumentation: ['', Validators.required],
  proofOfResidence: ['', Validators.required],
  selfie: ['', Validators.required],
  date: ['', Validators.required],
  auditor: ['', Validators.required],
});



 public getConsumerInfo() {
    const getConsumerInfoResponse = new GetConsumerInfoResponse(this.fakeResponse);

    this.registerForm.setValue({
      name: getConsumerInfoResponse.name,
      lastName: getConsumerInfoResponse.surName,
      gender: getConsumerInfoResponse.gender,
      dateBirth: getConsumerInfoResponse.birthDay,
      nationality: getConsumerInfoResponse.nationality,
      documentId: getConsumerInfoResponse.documentId,
      documentExpiryDate: getConsumerInfoResponse.expiryDate,
      documentIssueDate: getConsumerInfoResponse.issueDate,
      placeBirth: getConsumerInfoResponse.placeBirth,
      addressStreet: getConsumerInfoResponse.address.street_name,
      addressCity: getConsumerInfoResponse.address.city,
      addressIslandName: getConsumerInfoResponse.address.province,
      addressPostcode: getConsumerInfoResponse.address.postcode,
      nationalDocumentation: getConsumerInfoResponse.nationalDocumentation,
      proofOfResidence: getConsumerInfoResponse.proofOfResidence,
      selfie: getConsumerInfoResponse.selfie,
      date: getConsumerInfoResponse.date,
      auditor: getConsumerInfoResponse.auditor,
    });
    this.nationalIdentityDocument = getConsumerInfoResponse.nationalDocumentation;
    this.proofOfResidence = getConsumerInfoResponse.proofOfResidence;
    this.selfie = getConsumerInfoResponse.selfie;
    this.countrySelected = getConsumerInfoResponse.address.country;
    this.consumerName = getConsumerInfoResponse.name;
    this.consumerAddress =
      getConsumerInfoResponse.address.street_name +
      getConsumerInfoResponse.address.city +
      getConsumerInfoResponse.address.province +
      getConsumerInfoResponse.address.country;
    this.consumerBalance = getConsumerInfoResponse.balance;
    this.consumerEmail = getConsumerInfoResponse.email;
    this.consumerKyc = getConsumerInfoResponse.kyc;
    this.consumerPhone = getConsumerInfoResponse.phone;
    this.consumerStatus = getConsumerInfoResponse.consumerStatus;
    /* this.consumerInfoService.getConsumerInfo(this.appData.consumer_id).subscribe(
      (response) => {

      }
    ); */
    this.checkStatus(getConsumerInfoResponse);
  }
    
asked by Enric 14.05.2018 в 09:49
source

0 answers