1

I am new to ionic 2 and I could not find a proper solution for this.I have two radio buttons in my signup form. I need to enable two in put fields based on the radio button that is clicked. If radio button one is clicked input field one should be enabled.

Radio buttons

<div radio-group formGroupName="church">
<label>Church</label>
<div>
  <label>CGT</label>
  <ion-radio value="cgt" ></ion-radio>
  <label>Other church</label>
  <ion-radio value="noncgt"></ion-radio>
</div>
</div>
<div>

Input fields

<div>
      <label>CGT member ID </label>
      <input formControlName="cgtMemberID" type="text" disabled="true">
      <small [hidden]="myForm.controls.cgtMemberID.valid || (myForm.controls.cgtMemberID.pristine && !submitted)">
    member ID required .
    </small>
    </div>

    <div>
      <label>Church Name </label>
      <input formControlName="churchName" type="text" disabled="true">
      <small [hidden]="myForm.controls.churchName.valid || (myForm.controls.churchName.pristine && !submitted)">
      Church name required .
      </small>
    </div>
1

1 Answer 1

1

I think you need this:

1- in html:

<div radio-group>
    <label>Church</label>
    <div>
        <label>CGT</label>
        <ion-radio value="cgt" (ionSelect)="radio_select('cgt')"></ion-radio>
        <label>Other church</label>
        <ion-radio value="noncgt" (ionSelect)="radio_select('noncgt')"></ion-radio>
    </div>
</div>
<div>
    <label>CGT member ID </label>
    <input type="text" [disabled]="cgt">
</div>
<div>
    <label>Church Name </label>
    <input type="text" [disabled]="cn">
</div>

2- and in .ts file:

cgt: boolean = true;
cn: boolean = true;
radio_select(value) {
  if (value == 'cgt') {
    this.cgt = false;
    this.cn = true;
  } else if (value == 'noncgt') {
    this.cgt = true;
    this.cn = false;
  }
}

you also can add your form logic.

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

2 Comments

Runtime Error co.radio_select is not a function I get this error
I rebuild the whole code and it works now.Thanks alot.

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.