내 양식에는 "초안"및 "제출"이라는 두 개의 버튼이 있으므로 초안의 경우 일부 유효성 검사가 적용되고 제출 버튼에 대해서도 동일합니다. 하나의 변수 cmpnStatus가 있으며 값 1로 초기화됩니다. cpmnStatus의 초안 값은 0이고 제출의 경우 1입니다.
<div class="form-group">
<label>Short Description<span class="red-ast">*</span></label><br/>
<textarea ng-model="shortdesc" ng-change="shortchange(shortdesc)" class="form-control b-rad3" ng-required="cmpnStatus == 0"></textarea>
</div>
<button type="submit" ng-click="campform.$valid && submitDraft(campform)" class="btn btn-draft">Save as draft</button>
<button type="submit" class="btn btn-launch" ng-click="campform.$valid && submitCampaign()">Submit for Approval</button>
아래는 submitDraft 함수의 코드입니다.
$scope.submitDraft = function(form){
$scope.cmpnStatus = 0;
if(form.$valid) {
alert("valid");
} else {
alert("invalid");
}
//Then call to save data in db
};
내 문제는 초안 양식을 클릭하면 유효한 것으로 표시되고 db에 데이터를 저장 한 후 cpmnStatus의 초기 값이 1이고 조건에 따라 필요한 유효성 검사 조건이 실패하기 때문에 필요한 유효성 검사를 가리 킵니다. 다시 드래프트 버튼을 클릭하면 cpmnStatus의 값이 1에서 0으로 변경되기 때문에 필요한 유효성 검사가 제대로 작동합니다. 사용자가 드래프트 버튼을 클릭하고 cpmnStatus의 값이 변경되면 필요한 유효성 검사를 표시해야합니다 (첫 번째 클릭에서도 ) 조건 (ng-required = "cmpnStatus == 0")에 따라. 동일한 작업을 수행하는 다른 방법이 있습니까?
먼저 html을 다음과 같이 변경하십시오.
<button type="submit" ng-disabled="campform.$error" ng-click="submitDraft(campform)" class="btn btn-draft">Save as draft</button>
<button type="submit" class="btn btn-launch" ng-disabled="campform.$error" ng-click="submitCampaign()">Submit for Approval</button>
양식이 유효하지 않을 때 사용자에 대한 버튼을 비활성화하는 것이 좋습니다.
cmpnStatusThings 정보 확인란 또는 라디오 버튼을 사용하여 초안 또는 승인 모드 사이를 전환하는 것이 좋습니다.
<input type="checkbox" ng-model="cmpnStatus" ng-true-value="1" ng-false-value="0"/>
라디오 샘플 :
<input type="radio" ng-model="cmpnStatus" ng-value="1"/>
<input type="radio" ng-model="cmpnStatus" ng-value="0" />
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다