|
1 |
| -/*! forms-angular 2015-02-20 */ |
| 1 | +/*! forms-angular 2015-02-23 */ |
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | var formsAngular = angular.module('formsAngular', [
|
@@ -30,22 +30,6 @@ formsAngular.controller('BaseCtrl', [
|
30 | 30 |
|
31 | 31 | $rootScope.$broadcast('fngFormLoadStart', $scope);
|
32 | 32 |
|
33 |
| - // Invalid field styling for BS3 - only works for one level of nesting |
34 |
| - $scope.hasError = function(name, index) { |
35 |
| - var form = $scope[$scope.topLevelFormName]; |
36 |
| - var field; |
37 |
| - if (typeof index === 'undefined') { |
38 |
| - field = form['f_' + name.replace(/\./g,'_')]; |
39 |
| - } else { |
40 |
| - var parts = name.split('.'); |
41 |
| - form = form['form_' + parts[0] + index]; |
42 |
| - field = form[name.replace(/\./g,'-')]; |
43 |
| - } |
44 |
| - if (field && field.$invalid) { |
45 |
| - return true; |
46 |
| - } |
47 |
| - }; |
48 |
| - |
49 | 33 | formGenerator.decorateScope($scope, formGenerator, recordHandler, sharedStuff);
|
50 | 34 | recordHandler.decorateScope($scope, $modal, recordHandler, ctrlState);
|
51 | 35 |
|
@@ -303,7 +287,7 @@ formsAngular
|
303 | 287 | if (options.subschema && fieldInfo.name.indexOf('.') !== -1) {
|
304 | 288 | // Schema handling - need to massage the ngModel and the id
|
305 | 289 | var compoundName = fieldInfo.name;
|
306 |
| - var root = options.subschemaRoot; |
| 290 | + var root = options.subschemaroot; |
307 | 291 | var lastPart = compoundName.slice(root.length+1);
|
308 | 292 | if (options.index) {
|
309 | 293 | modelString += root + '[' + options.index + '].' + lastPart;
|
@@ -534,7 +518,7 @@ formsAngular
|
534 | 518 | for (var arraySel = 0; arraySel < subKeyArray.length; arraySel++) {
|
535 | 519 | var topAndTail = containerInstructions(subKeyArray[arraySel]);
|
536 | 520 | template += topAndTail.before;
|
537 |
| - template += processInstructions(info.schema, null, {subschema: true, formStyle: options.formstyle, subkey: schemaDefName + '_subkey', subkeyno: arraySel, subschemaRoot: info.name}); |
| 521 | + template += processInstructions(info.schema, null, {subschema: true, formStyle: options.formstyle, subkey: schemaDefName + '_subkey', subkeyno: arraySel, subschemaroot: info.name}); |
538 | 522 | template += topAndTail.after;
|
539 | 523 | }
|
540 | 524 | subkeys.push(info);
|
@@ -562,7 +546,7 @@ formsAngular
|
562 | 546 | template += ' </div> ';
|
563 | 547 | }
|
564 | 548 |
|
565 |
| - template += processInstructions(info.schema, false, {subschema: true, formstyle: info.formStyle, model: options.model, subschemaRoot: info.name}); |
| 549 | + template += processInstructions(info.schema, false, {subschema: true, formstyle: info.formStyle, model: options.model, subschemaroot: info.name}); |
566 | 550 |
|
567 | 551 | template += ' </div>' +
|
568 | 552 | '</div>';
|
@@ -814,7 +798,7 @@ formsAngular
|
814 | 798 | if (thisSubkeyList.hasOwnProperty(keyField)) {
|
815 | 799 | // Not (currently) concerned with objects here - just simple types and lookups
|
816 | 800 | if (dataVal[arrayOffset][keyField] !== thisSubkeyList[keyField] &&
|
817 |
| - (!dataVal[arrayOffset][keyField].text || dataVal[arrayOffset][keyField].text !== thisSubkeyList[keyField])) { |
| 801 | + (typeof dataVal[arrayOffset][keyField] === 'undefined' || !dataVal[arrayOffset][keyField].text || dataVal[arrayOffset][keyField].text !== thisSubkeyList[keyField])) { |
818 | 802 | matching = false;
|
819 | 803 | break;
|
820 | 804 | }
|
@@ -2006,7 +1990,19 @@ formsAngular.factory('formGenerator', function (
|
2006 | 1990 | $scope.setFormDirty($event);
|
2007 | 1991 | };
|
2008 | 1992 |
|
2009 |
| - exports.decorateScope = function($scope, formGeneratorInstance, recordHandlerInstance, sharedStuff) { |
| 1993 | + exports.hasError = function(formName, name, index, $scope) { |
| 1994 | + var form = $scope[$scope.topLevelFormName]; |
| 1995 | + if (formName !== 'null') { |
| 1996 | + form = form[formName.replace('$index', index)]; |
| 1997 | + } |
| 1998 | + var field = form[name]; |
| 1999 | + if (field && field.$invalid) { // am in two minds about adding && field.$dirty |
| 2000 | + return true; |
| 2001 | + } |
| 2002 | + }; |
| 2003 | + |
| 2004 | + |
| 2005 | + exports.decorateScope = function($scope, formGeneratorInstance, recordHandlerInstance, sharedStuff) { |
2010 | 2006 | $scope.record = sharedStuff.record;
|
2011 | 2007 | $scope.phase = 'init';
|
2012 | 2008 | $scope.disableFunctions = sharedStuff.disableFunctions;
|
@@ -2064,6 +2060,10 @@ formsAngular.factory('formGenerator', function (
|
2064 | 2060 | return formGeneratorInstance.add(fieldName, $event, $scope);
|
2065 | 2061 | };
|
2066 | 2062 |
|
| 2063 | + $scope.hasError = function(form, name, index) { |
| 2064 | + return formGeneratorInstance.hasError(form, name, index, $scope); |
| 2065 | + }; |
| 2066 | + |
2067 | 2067 | $scope.unshift = function (fieldName, $event) {
|
2068 | 2068 | return formGeneratorInstance.unshift(fieldName, $event, $scope);
|
2069 | 2069 | };
|
@@ -2157,7 +2157,21 @@ formsAngular.factory('formMarkupHelper', [
|
2157 | 2157 | classes += ' col-sm-' + inputSizeHelper.sizeAsNumber(info.size);
|
2158 | 2158 | closeTag += '</div>';
|
2159 | 2159 | }
|
2160 |
| - template += '<div' + addAllService.addAll(scope, 'Group', classes, options)+' ng-class="{\'has-error\': hasError(\'' + info.name + '\', $index)}"'; |
| 2160 | + |
| 2161 | + var modelControllerName; |
| 2162 | + var formName = null; |
| 2163 | + var parts = info.name.split('.'); |
| 2164 | + |
| 2165 | + if (options && typeof options.subkeyno !== 'undefined') { |
| 2166 | + modelControllerName = options.subschemaroot.replace(/\./g, '-') + '-subkey' + options.subkeyno + '-' + parts[parts.length-1]; |
| 2167 | + } else if (options.subschema) { |
| 2168 | + formName = 'form_' + parts[0] + '$index'; |
| 2169 | + modelControllerName = info.name.replace(/\./g, '-'); |
| 2170 | + } else { |
| 2171 | + modelControllerName = 'f_' + info.name.replace(/\./g,'_'); |
| 2172 | + } |
| 2173 | + |
| 2174 | + template += '<div' + addAllService.addAll(scope, 'Group', classes, options)+' ng-class="{\'has-error\': hasError(\'' + formName + '\',\'' + modelControllerName + '\', $index)}"'; |
2161 | 2175 | closeTag += '</div>';
|
2162 | 2176 | } else {
|
2163 | 2177 | if (exports.isHorizontalStyle(options.formstyle)) {
|
|
0 commit comments