Streamlined more of the validation directives, fixed up the regex val directive with the pre-value changes got validation working properly with the data type editor, finally on track with validation!
This commit is contained in:
@@ -36,11 +36,7 @@ function valPropertyMsg(serverValidationManager) {
|
||||
|
||||
//listen for error changes
|
||||
scope.$watch("formCtrl.$error", function () {
|
||||
if (formCtrl.$valid === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!formCtrl.$valid) {
|
||||
if (formCtrl.$invalid) {
|
||||
|
||||
//first we need to check if the valPropertyMsg validity is invalid
|
||||
if (formCtrl.$error.valPropertyMsg && formCtrl.$error.valPropertyMsg.length > 0) {
|
||||
|
||||
@@ -12,13 +12,12 @@ function valRegex() {
|
||||
link: function (scope, elm, attrs, ctrl) {
|
||||
|
||||
var regex;
|
||||
if (scope[attrs.valRegex]) {
|
||||
try {
|
||||
regex = new RegExp(scope.$eval(attrs.valRegex));
|
||||
}
|
||||
else {
|
||||
catch(e) {
|
||||
regex = new RegExp(attrs.valRegex);
|
||||
}
|
||||
|
||||
|
||||
var patternValidator = function (viewValue) {
|
||||
//NOTE: we don't validate on empty values, use required validator for that
|
||||
|
||||
@@ -18,14 +18,10 @@ function valTab() {
|
||||
scope.tabHasError = false;
|
||||
|
||||
//watch the current form's validation for the current field name
|
||||
scope.$watch("formCtrl.$valid", function (isValid, lastValue) {
|
||||
if (isValid === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
scope.$watch("formCtrl.$valid", function () {
|
||||
var tabContent = element.closest(".umb-panel").find("#" + tabId);
|
||||
|
||||
if (!isValid) {
|
||||
if (formCtrl.$invalid) {
|
||||
//check if the validation messages are contained inside of this tabs
|
||||
if (tabContent.find(".ng-invalid").length > 0) {
|
||||
scope.tabHasError = true;
|
||||
|
||||
@@ -14,19 +14,19 @@ function valToggleMsg(serverValidationManager) {
|
||||
if (!attr.valMsgFor){
|
||||
throw "valToggleMsg requires that the attribute valMsgFor exists on the element";
|
||||
}
|
||||
if (!formCtrl[attr.valMsgFor]) {
|
||||
throw "valToggleMsg cannot find field " + attr.valMsgFor + " on form " + formCtrl.$name;
|
||||
}
|
||||
|
||||
//we need to copy the form controller val to our isolated scope so that
|
||||
//we'll also maintain the current form name.
|
||||
scope[formCtrl.$name] = formCtrl;
|
||||
//assign the form control to our isolated scope so we can watch it's values
|
||||
scope.formCtrl = formCtrl;
|
||||
|
||||
//if there's any remaining errors in the server validation service then we should show them.
|
||||
var showValidation = serverValidationManager.items.length > 0;
|
||||
var hasError = false;
|
||||
|
||||
//add a watch to the validator for the value (i.e. myForm.value.$error.required )
|
||||
scope.$watch(formCtrl.$name + "." + attr.valMsgFor + ".$error." + attr.valToggleMsg, function (isInvalid, oldValue) {
|
||||
hasError = isInvalid;
|
||||
if (hasError && showValidation) {
|
||||
scope.$watch("formCtrl." + attr.valMsgFor + ".$error." + attr.valToggleMsg, function () {
|
||||
if (formCtrl[attr.valMsgFor].$error[attr.valToggleMsg] && showValidation) {
|
||||
element.show();
|
||||
}
|
||||
else {
|
||||
@@ -36,7 +36,7 @@ function valToggleMsg(serverValidationManager) {
|
||||
|
||||
scope.$on("saving", function(ev, args) {
|
||||
showValidation = true;
|
||||
if (hasError) {
|
||||
if (formCtrl[attr.valMsgFor].$error[attr.valToggleMsg]) {
|
||||
element.show();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div ng-form name="contentForm" ng-show="loaded">
|
||||
<form name="contentForm" ng-show="loaded">
|
||||
<umb-panel ng-controller="Umbraco.Editors.Content.EditController" val-show-validation>
|
||||
|
||||
<umb-header tabs="content.tabs">
|
||||
@@ -48,4 +48,4 @@
|
||||
</umb-tab-view>
|
||||
|
||||
</umb-panel>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div ng-form name="contentForm" ng-show="loaded">
|
||||
<form name="contentForm" ng-show="loaded">
|
||||
<umb-panel ng-controller="Umbraco.Editors.DataType.EditController" val-show-validation>
|
||||
|
||||
<umb-header>
|
||||
@@ -24,17 +24,13 @@
|
||||
<div class="umb-panel-body umb-scrollable row-fluid" auto-scale="1">
|
||||
<div class="tab-content form-horizontal">
|
||||
<div class="umb-pane">
|
||||
<umb-property property="properties.selectedEditor">
|
||||
|
||||
<!-- TODO: We have more issues with transcluding and ng-form so the current validator toggle is not
|
||||
executin, will investigate more tomorrow, if you are readin this, I discovered some crazy stuf with
|
||||
ng-form controllers and transclusion which makes things interesting. //-->
|
||||
<umb-property property="properties.selectedEditor">
|
||||
<div>
|
||||
<select name="selectedEditor"
|
||||
<select name="selectedEditor" id="selectedEditor"
|
||||
ng-model="availableEditors"
|
||||
required
|
||||
ng-options="e.name for e in content.availableEditors track by e.editorId"></select>
|
||||
<span class="help-inline" val-msg-for="selectedEditor" val-toggle-msg="requires">Requires</span>
|
||||
<span class="help-inline" val-msg-for="selectedEditor" val-toggle-msg="required">Required</span>
|
||||
</div>
|
||||
|
||||
</umb-property>
|
||||
@@ -46,4 +42,4 @@
|
||||
</div>
|
||||
|
||||
</umb-panel>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<ng-form name="contentForm" ng-show="loaded">
|
||||
<form name="contentForm" ng-show="loaded">
|
||||
<umb-panel ng-controller="Umbraco.Editors.Media.EditController" val-show-validation>
|
||||
<umb-header tabs="content.tabs">
|
||||
|
||||
@@ -32,4 +32,4 @@
|
||||
</umb-tab>
|
||||
</umb-tab-view>
|
||||
</umb-panel>
|
||||
</ng-form>
|
||||
</form>
|
||||
@@ -4,7 +4,7 @@
|
||||
</p>
|
||||
<input name="myPackage_postcode" type="text" ng-model="model.value"
|
||||
val-server="value"
|
||||
val-postcode="config.country"/>
|
||||
val-postcode="model.config.country"/>
|
||||
|
||||
<span class="help-inline" val-msg-for="myPackage_postcode" val-toggle-msg="valServer">{{propertyForm.myPackage_postcode.errorMsg}}</span>
|
||||
<span class="help-inline" val-msg-for="myPackage_postcode" val-toggle-msg="valPostcode">{{propertyForm.myPackage_postcode.errorMsg}}</span>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<input name="regex" id="regex"
|
||||
type="text" ng-model="model.value"
|
||||
required
|
||||
val-regex="config"
|
||||
val-regex="model.config[0]"
|
||||
val-server="value" />
|
||||
|
||||
<span class="help-inline" val-msg-for="regex" val-toggle-msg="required">Required!</span>
|
||||
|
||||
Reference in New Issue
Block a user