이 때 그 버튼을 클릭하면 다시 트리거하거나 모든 분야에 대한 검증 방법이 없을까?
angular.forEach($scope.myForm.$error.required, function(field) {
field.$setDirty();
});
그리고 당신이 사용하는 경우 유효함 양식은 확인할 수 있다.
if($scope.myForm.$valid) {
//Do something
}
마지막으로, 내 생각엔 전날에약혼자에게 그녀의심장을 변경하십시오 경우 라우트를 다 맛있어 보입니다.
$location.path('/somePath');
어떤 방법이 주효했는가 가져다줄래요 sanlight 설브미스테드 '기능을 사용하여 각 docs 에 있는' $ up in the fs@snapa 첫 버전 1.3.20.
Click 이벤트에 있는 내가 원하는 코스로 트리거할 검증, I did 다음과 같습니다.
vm.triggerSubmit = function() {
vm.homeForm.$setSubmitted();
...
}
그것은 모든 가져다줄래요 걸렸다. 이 문서 양식을 따르면, 해당 제출됨 state." " 설정합니다. # 39 에 언급된 it& [here] [1].
[1]: https://code.angularjs.org/1.3.20/docs/api/ng/type/form.FormController " here";
이 경우 나중에 누군가 돌아왔습니다. 기타 협력했습니다 for me. 그래서 내가 무덤을 찾은 근성이 아래쪽을 각도 양식 검증 기능을 실행할 수 있는 유럽인들은 검사기를 주어진 필드. 이 속성은 '$ 검증하십시오 편리하게 불렀으매'.
'콜' 양식 '라는 프로그램을 통해 마이포름 경우 $ 검증 ()' 을 autoexec. 현장 검증 myForm.my_field. 수 있습니다. 예를 들면 다음과 같습니다.
<div ng-form name="myForm">
<input required name="my_field" type="text" ng-blur="myForm.my_field.$validate()">
</div>
참고로 '$ 호출하십시오 모델에 대한 검증' 의 의미. 각 docs 에서 대한 검증: $ 영모델치를.
>. 각 레지스터링 검사기를 런입니다 (첫 번째 동기식 검사기를 그리곤요 비동기적입니다 검사기를). 이 모델은 변경되는지 유효성을 경우 잘못된 것은 정의되지 않은 한 영모들로티언스트라우로빈프리드 설정됩니다. 이 모델의 유효성을 정할 경우 변경되는지 유효함, 사용 가능한 마지막 유효함 $ 모델발루 인컨텍스트 마지막 값을 set 를 내시경이요 값이거나 마지막 구문 분석 (예:
만일 you&, re 모델 일을 준비하고 있는 잘못된 값을 # 39 와 같은 메시지를 전달하며 터지는 있도록) 한 후, '' true '로 설정되어 있는지 확인해야 합니다' 알로빈프리드 모델에 대한.
It will:*
[데모 보기] (http://plnkr.co/edit/WwIW5GtHokTiwpe689S3? p = 미리봅니다) *
예 *
<form angular-validator
angular-validator-submit="myFunction(myBeautifulForm)"
name="myBeautifulForm">
<!-- form fields here -->
<button type="submit">Submit</button>
</form>
'현장' 문법검사기 통과하지 못하는 경우 해당 사용자 양식이 제출됩니다 수 없게 된다.
각 문법검사기 활용 및 예 에서 자세한 내용을 확인해 보세요.
음, 각 방식으로 처리할 수 있도록 해야 합니다 - 약간만이라도 검증 결과 및 보이기 않기 때문에 모델 변경 - 수명주기의 모든 사용자에게 원할 때.
이 경우, 방금 설정해야 할 시점을 표시하십시오 오류뿐만 플래깅: http://plnkr.co/edit/0NNCpQKhbLTYMZaxMQ9l? p = 미리봅니다
우리는 각 파일링된 실행하십시오. 내린 것으로 알고 있습니다 수 있도록 더 진보된 제어입니다. 이 모든 것이 아니기 때문에 꼭 이래야겠어요 대신 기존 검증 방법을 사용하여 만 번 이상의 조회수를 기록하는 괴력을 발휘했다.
편집: 하지만, 이 경우 고객이 원하는 방식으로 준수하십시오 수정하고 전에 검증을 통해 제출됩니다 해야했다. http://plnkr.co/edit/Xfr7X6JXPhY9lFL3hnOw? p = 미리봅니다 이벤트가 컨트롤러 브로드캐스트에 버튼을 클릭할 때, 그리고 디렉티브을 높여줍니까 검증 매직.
모든 것이 한 가지 방법은 인력용 속성뿐 스크램블된 더러운. 하지만 과도한 얻을 수 있는 매우 컨트롤러마다 할 수 있습니다. 일반적인 솔루션을 할 게 좋을 것 같다.
내가 생각할 수 있는 가장 쉬운 방법은 디렉티브입니다 사용할 수 있었다
다음은 디렉티브을
myModule.directive('submit', function() {
return {
restrict: 'A',
link: function(scope, formElement, attrs) {
var form;
form = scope[attrs.name];
return formElement.bind('submit', function() {
angular.forEach(form, function(field, name) {
if (typeof name === 'string' && !name.match('^[\$]')) {
if (field.$pristine) {
return field.$setViewValue(field.$value);
}
}
});
if (form.$valid) {
return scope.$apply(attrs.submit);
}
});
}
};
});
양식 및 업데이트하십시오 html, 예를 들면 다음과 같습니다.
<form ng-submit='justDoIt()'>
됩니다.
<form name='myForm' novalidate submit='justDoIt()'>
전체 예를 볼 수 있습니다. http://plunker.co/edit/QVbisEK2WEbORTAWL7Gu? p = 미리봅니다
다음은 양식을 보여주는 내 글로벌 기능 오류 메시지.
function show_validation_erros(form_error_object) {
angular.forEach(form_error_object, function (objArrayFields, errorName) {
angular.forEach(objArrayFields, function (objArrayField, key) {
objArrayField.$setDirty();
});
});
};
그리고 제 모든 컨트롤러에서는
if ($scope.form_add_sale.$invalid) {
$scope.global.show_validation_erros($scope.form_add_sale.$error);
}
내 양식 필드 보이기 때문에 검사 메시지, 그리고 내가 그동안 잘못된 경우 사용자가 필드는 가질 수 있었던 것은 이 코드를 사용하여 트리거됨 표시하십시오 의해 버튼를 내 잘못된 필드:
<! - begin 스니핏: js 숨기십시오: > 거짓값 -;
// Show/trigger any validation errors for this step
angular.forEach(vm.rfiForm.stepTwo.$error, function(error) {
angular.forEach(error, function(field) {
field.$setTouched();
});
});
// Prevent user from going to next step if current step is invalid
if (!vm.rfiForm.stepTwo.$valid) {
isValid = false;
}
<!-- form field -->
<div class="form-group" ng-class="{ 'has-error': rfi.rfiForm.stepTwo.Parent_Suffix__c.$touched && rfi.rfiForm.stepTwo.Parent_Suffix__c.$invalid }">
<!-- field label -->
<label class="control-label">Suffix</label>
<!-- end field label -->
<!-- field input -->
<select name="Parent_Suffix__c" class="form-control"
ng-options="item.value as item.label for item in rfi.contact.Parent_Suffixes"
ng-model="rfi.contact.Parent_Suffix__c" />
<!-- end field input -->
<!-- field help -->
<span class="help-block" ng-messages="rfi.rfiForm.stepTwo.Parent_Suffix__c.$error" ng-show="rfi.rfiForm.stepTwo.Parent_Suffix__c.$touched">
<span ng-message="required">this field is required</span>
</span>
<!-- end field help -->
</div>
<!-- end form field -->
끝 - < 스니핏 >;!
참고: 내가 아는 이는 해킹, 그 당시 각 1.2 와 t 는 이에 앞서 didn& # 39, 간단한 방법을 유용합니다.
발로 검증에 대해 이벤트 때문에 일부 프로그래밍 방식으로 변경, t # 39 와 같은 것들을 값을 변경하면 won& 트리거할 거잖나. 그러나 트리거합니다 행사는 변경하십시오 트리거하여 검증. 예를 들어, 함께 포함한다.
$('#formField1, #formField2').trigger('change');
이 문제를 해결할 수 있습니다.
<! - begin 스니핏: js 숨기십시오: > 거짓값 -;
// The controller
$scope.submitForm = function(form){
//Force the field validation
angular.forEach(form, function(obj){
if(angular.isObject(obj) && angular.isDefined(obj.$setDirty))
{
obj.$setDirty();
}
})
if (form.$valid){
$scope.myResource.$save(function(data){
//....
});
}
}
<!-- FORM -->
<form name="myForm" role="form" novalidate="novalidate">
<!-- FORM GROUP to field 1 -->
<div class="form-group" ng-class="{ 'has-error' : myForm.field1.$invalid && myForm.field1.$dirty }">
<label for="field1">My field 1</label>
<span class="nullable">
<select name="field1" ng-model="myresource.field1" ng-options="list.id as list.name for list in listofall"
class="form-control input-sm" required>
<option value="">Select One</option>
</select>
</span>
<div ng-if="myForm.field1.$dirty" ng-messages="myForm.field1.$error" ng-messages-include="mymessages"></div>
</div>
<!-- FORM GROUP to field 2 -->
<div class="form-group" ng-class="{ 'has-error' : myForm.field2.$invalid && myForm.field2.$dirty }">
<label class="control-label labelsmall" for="field2">field2</label>
<input name="field2" min="1" placeholder="" ng-model="myresource.field2" type="number"
class="form-control input-sm" required>
<div ng-if="myForm.field2.$dirty" ng-messages="myForm.field2.$error" ng-messages-include="mymessages"></div>
</div>
</form>
<!-- ... -->
<button type="submit" ng-click="submitForm(myForm)">Send</button>
끝 - < 스니핏 >;!
내가 뭔가 수행됨 정보정의다음 할 것이다.
<form name="form" name="plantRegistrationForm">
<div ng-class="{ 'has-error': (form.$submitted || form.headerName.$touched) && form.headerName.$invalid }">
<div class="col-md-3">
<div class="label-color">HEADER NAME
<span class="red"><strong>*</strong></span></div>
</div>
<div class="col-md-9">
<input type="text" name="headerName" id="headerName"
ng-model="header.headerName"
maxlength="100"
class="form-control" required>
<div ng-show="form.$submitted || form.headerName.$touched">
<span ng-show="form.headerName.$invalid"
class="label-color validation-message">Header Name is required</span>
</div>
</div>
</div>
<button ng-click="addHeader(form, header)"
type="button"
class="btn btn-default pull-right">Add Header
</button>
</form>
In your 컨트롤러거 행하는모든 수 있습니다.
addHeader(form, header){
let self = this;
form.$submitted = true;
...
}
Css 도 일부 합니다.
.label-color {
color: $gray-color;
}
.has-error {
.label-color {
color: rgb(221, 25, 29);
}
.select2-choice.ui-select-match.select2-default {
border-color: #e84e40;
}
}
.validation-message {
font-size: 0.875em;
}
.max-width {
width: 100%;
min-width: 100%;
}