@@ -1092,47 +1092,63 @@ module fng.services {
1092
1092
$scope . whyDisabled = undefined ;
1093
1093
let pristine = false ;
1094
1094
1095
- if ( $scope [ $scope . topLevelFormName ] ) {
1096
- if ( $scope [ $scope . topLevelFormName ] . $invalid ) {
1097
- $scope . whyDisabled = 'The form data is invalid:' ;
1098
- $scope [ $scope . topLevelFormName ] . $$controls . forEach ( c => {
1099
- if ( c . $invalid ) {
1100
- $scope . whyDisabled += '<br /><strong>' ;
1101
-
1095
+ function generateWhyDisabledMessage ( form , subFormName ?: string ) {
1096
+ form . $$controls . forEach ( c => {
1097
+ if ( c . $invalid ) {
1098
+ if ( c . $$controls ) {
1099
+ // nested form
1100
+ generateWhyDisabledMessage ( c , c . $name )
1101
+ } else {
1102
+ $scope . whyDisabled += "<br /><strong>" ;
1103
+ if ( subFormName ) {
1104
+ $scope . whyDisabled += subFormName + ' ' ;
1105
+ }
1102
1106
if (
1103
- cssFrameworkService . framework ( ) === ' bs2' &&
1107
+ cssFrameworkService . framework ( ) === " bs2" &&
1104
1108
c . $$element &&
1105
1109
c . $$element . parent ( ) &&
1106
1110
c . $$element . parent ( ) . parent ( ) &&
1107
- c . $$element . parent ( ) . parent ( ) . find ( ' label' ) &&
1108
- c . $$element . parent ( ) . parent ( ) . find ( ' label' ) . text ( )
1111
+ c . $$element . parent ( ) . parent ( ) . find ( " label" ) &&
1112
+ c . $$element . parent ( ) . parent ( ) . find ( " label" ) . text ( )
1109
1113
) {
1110
- $scope . whyDisabled += c . $$element . parent ( ) . parent ( ) . find ( ' label' ) . text ( )
1114
+ $scope . whyDisabled += c . $$element . parent ( ) . parent ( ) . find ( " label" ) . text ( ) ;
1111
1115
} else if (
1112
- cssFrameworkService . framework ( ) === ' bs3' &&
1116
+ cssFrameworkService . framework ( ) === " bs3" &&
1113
1117
c . $$element &&
1114
1118
c . $$element . parent ( ) &&
1115
1119
c . $$element . parent ( ) . parent ( ) &&
1116
1120
c . $$element . parent ( ) . parent ( ) . parent ( ) &&
1117
- c . $$element . parent ( ) . parent ( ) . parent ( ) . find ( ' label' ) &&
1118
- c . $$element . parent ( ) . parent ( ) . parent ( ) . find ( ' label' ) . text ( )
1121
+ c . $$element . parent ( ) . parent ( ) . parent ( ) . find ( " label" ) &&
1122
+ c . $$element . parent ( ) . parent ( ) . parent ( ) . find ( " label" ) . text ( )
1119
1123
) {
1120
- $scope . whyDisabled += c . $$element . parent ( ) . parent ( ) . parent ( ) . find ( ' label' ) . text ( )
1124
+ $scope . whyDisabled += c . $$element . parent ( ) . parent ( ) . parent ( ) . find ( " label" ) . text ( ) ;
1121
1125
} else {
1122
1126
$scope . whyDisabled += c . $name ;
1123
1127
}
1124
- $scope . whyDisabled += ' </strong>: ' ;
1128
+ $scope . whyDisabled += " </strong>: " ;
1125
1129
if ( c . $error ) {
1126
1130
for ( let type in c . $error ) {
1127
1131
switch ( type ) {
1128
- case 'required' : $scope . whyDisabled += 'Field missing required value. ' ; break ;
1129
- case 'pattern' : $scope . whyDisabled += 'Field does not match required pattern. ' ; break ;
1130
- default : $scope . whyDisabled += type + '. ' ;
1132
+ case "required" :
1133
+ $scope . whyDisabled += "Field missing required value. " ;
1134
+ break ;
1135
+ case "pattern" :
1136
+ $scope . whyDisabled += "Field does not match required pattern. " ;
1137
+ break ;
1138
+ default :
1139
+ $scope . whyDisabled += type + ". " ;
1131
1140
}
1132
1141
}
1133
1142
}
1134
1143
}
1135
- } )
1144
+ }
1145
+ } ) ;
1146
+ }
1147
+
1148
+ if ( $scope [ $scope . topLevelFormName ] ) {
1149
+ if ( $scope [ $scope . topLevelFormName ] . $invalid ) {
1150
+ $scope . whyDisabled = 'The form data is invalid:' ;
1151
+ generateWhyDisabledMessage ( $scope [ $scope . topLevelFormName ] ) ;
1136
1152
} else if ( $scope [ $scope . topLevelFormName ] . $pristine ) {
1137
1153
// Don't have disabled message - should be obvious from Cancel being disabled,
1138
1154
// and the message comes up when the Save button is clicked.
0 commit comments