单击时禁用单选按钮

时间:2020-05-05 14:05:44

标签: html angular

我有一个不同答案的表格。我的表单控件之一是单选按钮。当我单击此单选按钮之一时,所有其他单选按钮都会启用。

 <form [formGroup]="formAnswers">
                      <!-- body risposte -->
                      <div *ngFor="let answer of questions.answers; let n = index;" class="row mb-1 border-bottom">
                        <!-- checkbox -->
                        <div
                          class="col-xs-1 col-sm-1 col-md-1 col-lg-1 text-left form-check form-check-inline pl-1">
                          <input formControlName="idAnswerRadio" class="form-check-input cursor-pointer radio-button"
                            type="radio" (click)="manageAnswer(n)">
                        </div>
                        <div class="col-xs-9 col-sm-9 col-md-9 col-lg-9 text-left risposta-wrap">
                          {{answer.text}}
                        </div>
                        <div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 text-center">
                          {{answer.value}}
                        </div>
                      </div>
 </form>


  createFormAnswer(questions?: Questions[]) {
                                for (let i = 0; i < domande.length; i++) {
                                // other formcontrols questions
                                     for (let n = 0; n < questions[i].answers.length; n++) {
                                        this.formAnswers = this.formBuilder.group({
                                         idAnswerRadio: []
                                })
                              }
                         }
                      }

上面的代码是用于创建答案表格的代码。不幸的是,我无法添加stackblitz

1 个答案:

答案 0 :(得分:0)

您可以绑定到条件' Rout Document to the Correct Validation step. Private Sub Batch_Close(ByVal pXRootFolder As CASCADELib.CscXFolder, ByVal CloseMode As CASCADELib.CscBatchCloseMode) Dim i As Long Dim mandat As String Dim lVal As Long Dim strVal As String Dim oXDocInfo As CASCADELib.CscXDocInfo Dim folder As CASCADELib.CscXFolder ' only enter after extraction and after validation If CloseMode = CASCADELib.CscBatchCloseFinal Then If Project.ScriptExecutionMode = CscScriptModeServer Or Project.ScriptExecutionMode = CscScriptModeValidation Then ' get root folder Set folder = pXRootFolder While Not folder.IsRootFolder Set folder = folder.ParentFolder Wend ' get batch name mandat = folder.XValues.ItemByName("AC_BATCH_CLASS_NAME").Value lVal = 0 strVal = "" Select Case mandat Case "x" lVal = 0 Case "y" lVal = 2 End Select strVal = CStr(lVal) If Project.ScriptExecutionMode = CscScriptModeValidation Then For i = 0 To folder.GetTotalDocumentCount - 1 Set oXDocInfo = folder.GetDocInfoByGlobalIndex(i) oXDocInfo.XValues.Set("KTM_DOCUMENTROUTING", strVal) Next folder.XValues.Set("KTM_DOCUMENTROUTING_QUEUE_" & strVal, "kfxpdf.exe") ElseIf Project.ScriptExecutionMode = CscScriptModeServer Then For i = 0 To folder.GetTotalDocumentCount - 1 Set oXDocInfo = folder.GetDocInfoByGlobalIndex(i) oXDocInfo.XValues.Set("KTM_DOCUMENTROUTING", strVal) oXDocInfo.XDocument.NextValidationInstance = lVal Next ' validation is not done => rout to the depending validation instance If(lVal = 0) Then folder.XValues.Set("KTM_DOCUMENTROUTING_QUEUE_" & strVal, "KTM.Validation") Else folder.XValues.Set("KTM_DCOUMENTROUTING_QUEUE_" & strVal, "KTM.Validation") folder.XValues.Set("KTM_DOCUMENTROUTING_QUEUE_" & strVal, "KTM.Validation" & strVal) pXRootFolder.Valid = False End If End If End If End If End Sub 属性中,以更改每个disable按钮。 另外,您可以在“主”单选按钮上监听更改,以在其值更改时做出反应。

示例:

打字稿文件:

radio

HTML文件:

private isAnswerRadio: boolean = false;

public formAnswers: FormGroup = new FormGroup({
  'isAnswerRadio': new FormControl(...),
  // Other form controls (Initially disabled)
  '...': new FormControl(...),
  ...
});

ngOnInit() {
  this.formAnswers.get('isAnswerRadio').valueChanges.subscribe(newData => {
      if(newData === ...) { // If equals to the desired selection of the radio button
        this.isAnswersRadio = true;
      }
  });
}

getDisabled(): boolean {
  return this.isAnswerRadio;
}