2017-10-12 21 views
0

我有一個註冊表單,其中包含多於1個json-schema-form。如果json-schema-form無效,Angular4禁用按鈕

我有參與者必須填寫的基本細節,並且我有兩個動態的部分表格。這兩個表單只會在管理員爲表單設置參數時纔會顯示。

 <div class="registration-form"> 
     <json-schema-form [model]="participantEventInfo" [schema]="json_custom_form" (isValid)="isEventFormValid($event)" (onChanges)="updateParticipantEventInfo($event)"></json-schema-form> 
     <json-schema-form [model]="participantTixInfo" [schema]="json_tix_custom_form" (onChanges)="updateParticipantTixInfo($event)" (isValid)="isTixFormValid($event)"></json-schema-form> 
     <button type="submit" [disabled]="!participantEventInfo.isValid && !participantTixInfo.isValid" (click)="updateEventandTixInfoRegistration()">Update</button> 
    </div> 

所以現在我有2個json-schema-form,一個用於事件信息,一個用於票據信息。我想禁用提交按鈕,所以在我的提交按鈕中,我想禁用buttton是不是填充的架構表單。但是,根據我的代碼,即使我填寫了所有表單域,該按鈕始終處於禁用狀態。我是否正確地執行了禁用部分?

謝謝。

+0

請發表您的component.ts代碼。 –

回答

0

嘗試檢查這兩個和禁用按鈕

<button type="submit" [disabled]="!checkForm()" click)="updateEventandTixInfoRegistration()">Update</button> 

checkForm(){ 
    if(document.forms[0].checkValidity() && document.forms[1].checkValidity()){ 
     return true; 
    } 
    else{ 
     return false; 
    } 
}