0

I know this question has been asked and answered multiple times, but I cannot seem figure out how to implement them into my application. I am pretty new to Ionic and Angular.

I have a dropdown checkbox list where a user can select one or more answers. I need the values selected to be sent as a string. When submitting the form, I get this error. This error occurs regardless of if it is one or more answers.

enter image description here

HTML

    <ion-item>
      <ion-label stacked>1. Type of Incident or Observation</ion-label>
      <ion-select multiple="true" formControlName="firstQuestionAnswer" required [(ngModel)]="stopCardRequest.firstQuestionAnswer">
        <ion-option *ngFor="let firstQuestionAnswer of firstQuestionOptions" value="{{firstQuestionAnswer.value}}">{{firstQuestionAnswer.name}}</ion-option>
      </ion-select>
    </ion-item>

TS

  firstQuestionOptions = [
    { name: "Near Miss", value: "Near Miss" },
    { name: "First Aid", value: "First Aid" },
    { name: "Medical Beyond First Aid (HSE will conduct investigation)", value: "Medical Beyond First Aid (HSE will conduct investigation)" },
    { name: "Lost Time", value: "Lost Time" },
    { name: "Environmental (spills / releases)" ,value: "Environmental (spills / releases)" },
    { name: "Security", value: "Security" },
    { name: "Vehicle / Equipment Incident", value: "Vehicle / Equipment Incident" },
    { name: "Fire", value: "Fire"  },
    { name: "Illness", value: "Illness" },
    { name: "General Observation", value: "General Observation" }
  ];

  public submitRequest(values) {
    this.showLoading().then(() => {
      this.stopCardProvider.save(this.stopCardRequest).subscribe(
        () => {
          this.logger.info("Stop Card sent");
          this.alertProvider.showSubmission();
          this.stopCardForm.reset();
          // Dismiss loading overlay.
          this.loading.dismiss();
        },
        error => {
          // Dismiss loading overlay.
          this.loading.dismiss();
          this.alertProvider.showError(error);
        });
    });
  }

In the model, the firstQuestionAnswer is a string. I am not sure what else anyone would need to answer this, so please let me know and I will give you what I can.

1 Answer 1

1

You can convert your array to string and pass it whenever you can

Here ex:

this.selectedItem=["Banana", "Orange", "Apple", "Mango"]; this.selectedItem=this.selectedItem.toString();

Sign up to request clarification or add additional context in comments.

Comments

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.