|
25 | 25 | * <ul style='list-style-type: none'>
|
26 | 26 | * <li>.label - the text to display on the button
|
27 | 27 | * <li>.class - (optional) classes to add to the button
|
28 |
| - * <li>.actionFn - (optional) user defined function to call when the button is clicked |
| 28 | + * <li>.actionFn - (optional) user defined function to call when the button is clicked. May optionally return false |
| 29 | + * to prevent closing the modal. For example to perfrom asynchronous validations. |
29 | 30 | * <li>.isDisabled - (optional) boolean true if the button should be disabled by default
|
30 |
| - * <li>.isCancel - (optional) boolean true is the button should cancel and dismiss the modal |
| 31 | + * <li>.isCancel - (optional) boolean true if the button should cancel and dismiss the modal |
31 | 32 | * </ul>
|
32 | 33 | * @param {string=} titleId Id of the title. "modalTitle" by default
|
33 | 34 | * @param {boolean=} hideCloseIcon Flag indicating that the modal should hide the 'x' close icon.
|
|
39 | 40 | * @param {object=} modalBodyScope Object containing the scope for the modalBodyTemplate
|
40 | 41 | *
|
41 | 42 | * @example
|
42 |
| - <example module="patternfly.modals"> |
| 43 | + <example module="patternfly.modals.demo"> |
| 44 | +
|
| 45 | + <file name="modules.js"> |
| 46 | + angular.module('patternfly.modals.demo', ['patternfly.modals', 'patternfly.notification']); |
| 47 | + </file> |
43 | 48 |
|
44 | 49 | <file name="index.html">
|
45 | 50 | <div ng-controller="DemoModalOverlayCtrl" class="example-container">
|
|
76 | 81 | </file>
|
77 | 82 |
|
78 | 83 | <file name="script.js">
|
79 |
| - angular.module('patternfly.modals').controller('DemoModalOverlayCtrl', function( $scope ) { |
| 84 | + angular.module('patternfly.modals.demo').controller('DemoModalOverlayCtrl', function( $scope, $timeout ) { |
80 | 85 |
|
81 | 86 | $scope.actionsText = "";
|
82 | 87 |
|
|
110 | 115 | third: ""
|
111 | 116 | },
|
112 | 117 | allowBackgroundDismissal: false,
|
113 |
| - showNotAllowedMsg: false |
| 118 | + showNotAllowedMsg: false, |
| 119 | + maxLength: 6, |
| 120 | + firstInputInvalid: false, |
| 121 | + validating: false, |
| 122 | + formErrorNotification: { |
| 123 | + type: "danger", |
| 124 | + header: "Input is not valid.", |
| 125 | + message: "Fix the errors below to continue saving." |
| 126 | + } |
114 | 127 | };
|
115 | 128 | $scope.actionButtons = [
|
116 | 129 | {
|
|
121 | 134 | label: "Save",
|
122 | 135 | class: "btn-primary custom-class",
|
123 | 136 | actionFn: function() {
|
124 |
| - $scope.actionsText = "inputs {" + |
| 137 | + $scope.actionsText = "inputs {" + |
125 | 138 | "\n first: " + $scope.formScope.inputs.first +
|
126 | 139 | "\n second: " + $scope.formScope.inputs.second +
|
127 | 140 | "\n third: " + $scope.formScope.inputs.third +
|
128 | 141 | "\n}" + $scope.actionsText;
|
| 142 | + $scope.formScope.firstInputInvalid = false; |
| 143 | + $scope.formScope.validating = true; |
| 144 | + $timeout(function () { |
| 145 | + $scope.formScope.validating = false; |
| 146 | + if ($scope.formScope.inputs.first === 'apples') { |
| 147 | + $scope.showModal = false; |
| 148 | + } else { |
| 149 | + $scope.formScope.firstInputInvalid = true; |
| 150 | + } |
| 151 | + }, 3000); |
| 152 | + return false; |
129 | 153 | }
|
130 | 154 | }];
|
131 | 155 |
|
|
157 | 181 |
|
158 | 182 | <file name="demo-form.html">
|
159 | 183 | <ng-form name="demoForm" class="form-horizontal">
|
| 184 | + <pf-inline-notification ng-if="$ctrl.modalBodyScope.firstInputInvalid" |
| 185 | + pf-notification-type="$ctrl.modalBodyScope.formErrorNotification.type" |
| 186 | + pf-notification-header="$ctrl.modalBodyScope.formErrorNotification.header" |
| 187 | + pf-notification-message="$ctrl.modalBodyScope.formErrorNotification.message"> |
| 188 | + </pf-inline-notification> |
160 | 189 | <div class="form-group">
|
161 | 190 | <label class="col-sm-3 control-label required-pf" for="textInput">Field One</label>
|
162 |
| - <div class="col-sm-9"> |
163 |
| - <input type="text" id="textInput" class="form-control" ng-model="$ctrl.modalBodyScope.inputs.first" ng-required="true"/> |
| 191 | + <div class="col-sm-9" |
| 192 | + ng-class="{ 'has-error': demoForm.fieldOne.$dirty && demoForm.fieldOne.$touched && $ctrl.modalBodyScope.firstInputInvalid}"> |
| 193 | + <input type="text" id="textInput" name="fieldOne" class="form-control" |
| 194 | + ng-model="$ctrl.modalBodyScope.inputs.first" ng-required="true"/> |
| 195 | + <div class="has-error" ng-show="$ctrl.modalBodyScope.firstInputInvalid"> |
| 196 | + <span class="help-block"> |
| 197 | + Invalid value for Field One. Only acceptable value is 'apples' |
| 198 | + </span> |
| 199 | + </div> |
164 | 200 | </div>
|
165 | 201 | </div>
|
166 | 202 | <div class="form-group">
|
167 | 203 | <label class="col-sm-3 control-label" for="textInput2">Field Two</label>
|
168 |
| - <div class="col-sm-9"> |
169 |
| - <input type="text" id="textInput2" class="form-control" ng-model="$ctrl.modalBodyScope.inputs.second"/> |
| 204 | + <div class="col-sm-9" |
| 205 | + ng-class="{ 'has-error': demoForm.fieldTwo.$dirty && demoForm.fieldTwo.$touched && demoForm.fieldTwo.$error.maxlength}" > |
| 206 | + <input type="text" name="fieldTwo" id="textInput2" class="form-control" |
| 207 | + ng-model="$ctrl.modalBodyScope.inputs.second" |
| 208 | + ng-maxlength="$ctrl.modalBodyScope.maxLength" /> |
| 209 | + <div class="has-error" ng-show="demoForm.fieldTwo.$error.maxlength"> |
| 210 | + <span class="help-block"> |
| 211 | + Field Two exceeds max length of {{$ctrl.modalBodyScope.maxLength}}! |
| 212 | + </span> |
| 213 | + </div> |
170 | 214 | </div>
|
171 | 215 | </div>
|
172 | 216 | <div class="form-group">
|
|
187 | 231 | </div>
|
188 | 232 | </div>
|
189 | 233 | </div>
|
| 234 | + <div ng-if="$ctrl.modalBodyScope.validating"> |
| 235 | + <div class="spinner spinner-lg blank-slate-pf-icon"></div> |
| 236 | + </div> |
190 | 237 | </ng-form>
|
191 | 238 | </file>
|
192 | 239 |
|
|
0 commit comments