Getting the value from a radio-list using FormGroup

#1

EDIT: Fixed it! My issue was simply to declare the [value]=“challenge” in the correct place - in this example I needed to declare it inside the ion-radio HTML tag. If anyone else is new to Ionic/Angular and is getting stuck with this: make sure the [value] tag lies inside an actual form-type-thing, i.e. textfield, password field, radio-button, checkbox etc.

I have been trying (hopelessly) to take a value from a radio-list form and return its name on another page. Currently I am not really getting an error - rather the challenge object does not seem to be getting passed to the other page at all! All the objects in the array list are listed using their names and it is the name that I need to pass to the other page. Here is my HTML:

<form [formGroup]="challengeForm" (ngSubmit)="logchallengeForm(form)">
  <ion-list radio-group formControlName="challenge" name="radio" >
    <ion-list-header>OR SELECT FROM THE LIST:</ion-list-header>
    <ion-item  *ngFor="let challenge of challengeList">
      <ion-label >{{challenge.name}}</ion-label>
      <ion-radio (ionSelect)="select(challenge)" ></ion-radio>
    </ion-item>
    <button ion-button full color="primary" type="submit">Save challenge</button>
  </ion-list>
</form>

Here is how I declared the FormGroup in the constructor:

this.challengeForm = formBuilder.group({
      challenge: ['']
});

And here is my logChallengeForm(form) method:

logOcaChallengeForm(form){
    this.challengeProvider.addChallenge(this.challengeForm.value.challenge);
    this.navCtrl.push(ChallengePage);
}

The addChallenge method in the provider literally just pushes the given object into an array.

Definitely part of the problem is that I am unable to find and adapt other peoples’ forms from the internet! They all seem to be using slightly different versions of Ionic/Angular/TypeScript/JS which, with my lack of experience, I am getting confused over. Can anyone spot what I’m doing wrong? Thanks!

#2

-> They all seem to be using slightly different versions of Ionic/Angular/TypeScript/JS

A recent tutorial: https://robferguson.org/blog/2017/11/19/ionic-3-and-forms/

My ionic info:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

local packages:

    @ionic/app-scripts : 3.1.2
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.9.1
    npm  : 5.5.1 
    OS   : macOS Sierra

Misc:

    backend : pro
#3

Thanks for your help, I was eventually able to solve it after a few more hours of comparing with this blog!

#4

Getting issue when after deploy of ionic ,
we need this one issue : No value accessor for form control with name: ‘challenge’

#5

can you please help to resolving this issue >>>>



=-=-=-=-=-=-=-=-=-=-

Page:: order.ts>>>>

in constructo(){
this.AddOrderForm = this.formBuilder.group({
orderController: [’’]
});
}


getOrders(form){
console.log(this.AddOrderForm.value.orderController);
}


=-=-=-=-=-=-=-=


but i can’t able to getting form value after submit…
:frowning: