|
102 | 102 | // }).popover("show");
|
103 | 103 | //};
|
104 | 104 |
|
| 105 | + var hideValidation = function () |
| 106 | + { |
| 107 | + validator.settings.unhighlight(editor); |
| 108 | + |
| 109 | + // TODO: do we need this if app has proper bs highlight method? |
| 110 | + editor.parents(".form-group").removeClass("has-error"); |
| 111 | + |
| 112 | + template.popover("hide"); |
| 113 | + }; |
| 114 | + |
| 115 | + var hideEditor = function () |
| 116 | + { |
| 117 | + template.hide(); |
| 118 | + |
| 119 | + hideValidation(); |
| 120 | + }; |
| 121 | + |
| 122 | + var doValidation = function () |
| 123 | + { |
| 124 | + var isValid = editor.valid(); |
| 125 | + |
| 126 | + if (isValid) |
| 127 | + { |
| 128 | + hideValidation(); |
| 129 | + } |
| 130 | + else |
| 131 | + { |
| 132 | + validator.settings.highlight(editor); |
| 133 | + |
| 134 | + // TODO: do we need this if app has proper bs highlight method? |
| 135 | + editor.parents(".form-group").addClass("has-error"); |
| 136 | + |
| 137 | + window.setTimeout(function () |
| 138 | + { |
| 139 | + $(template) |
| 140 | + .popover( |
| 141 | + { |
| 142 | + container: "body", |
| 143 | + content: function () { return validator.errorList[0].message; } |
| 144 | + }) |
| 145 | + .popover("show"); |
| 146 | + }, 100); |
| 147 | + } |
| 148 | + |
| 149 | + return isValid; |
| 150 | + }; |
| 151 | + |
| 152 | + var handleBlur = function () |
| 153 | + { |
| 154 | + // TODO: is there a more efficient way for this? |
| 155 | + if (!$(document.activeElement).parents().is(template)) |
| 156 | + { |
| 157 | + if (editor.valid()) |
| 158 | + { |
| 159 | + active.text(editor.val()); |
| 160 | + |
| 161 | + hideEditor(); |
| 162 | + } |
| 163 | + else |
| 164 | + { |
| 165 | + editor.focus(); |
| 166 | + |
| 167 | + doValidation(); |
| 168 | + } |
| 169 | + } |
| 170 | + }; |
| 171 | + |
105 | 172 | template
|
106 | 173 | .show()
|
107 | 174 | .offset(active.offset())
|
108 | 175 | .width(template == editor ? active.width() : active.outerWidth())
|
109 |
| - .height(template == editor ? active.height() : active.outerHeight()); |
| 176 | + .height(template == editor ? active.height() : active.outerHeight()) |
| 177 | + .off("blur") |
| 178 | + .on("blur", function() |
| 179 | + { |
| 180 | + setTimeout(handleBlur, 1); |
| 181 | + }); |
110 | 182 |
|
111 | 183 | editor.val(active.text())
|
112 | 184 | .removeClass('error')
|
113 | 185 | .css(active.css(self.options.cloneProperties))
|
114 | 186 | .height(active.height())
|
115 | 187 | .focus()
|
116 |
| - .off("blur") |
117 |
| - .on("blur", function() |
118 |
| - { |
119 |
| - active.text(editor.val()); |
120 |
| - template.hide(); |
121 |
| - template.popover("hide"); |
122 |
| - }) |
123 | 188 | .off("keydown")
|
124 | 189 | .on("keydown", function (e)
|
125 | 190 | {
|
126 | 191 | if (e.which === ENTER)
|
127 | 192 | {
|
128 |
| - //active.text(editor.val()); |
129 |
| - //setActiveText(); |
| 193 | + if (doValidation()) |
| 194 | + { |
| 195 | + template.hide(); |
| 196 | + active.focus(); |
| 197 | + |
| 198 | + var possibleMove = movement(active, e.shiftKey ? ARROW_UP : ARROW_DOWN); |
130 | 199 |
|
131 |
| - template.hide(); |
132 |
| - active.focus(); |
| 200 | + if (possibleMove.length > 0) |
| 201 | + { |
| 202 | + possibleMove.focus(); |
133 | 203 |
|
134 |
| - e.preventDefault(); |
135 |
| - e.stopPropagation(); |
| 204 | + e.preventDefault(); |
| 205 | + e.stopPropagation(); |
| 206 | + } |
| 207 | + } |
136 | 208 | }
|
137 | 209 | else if (e.which === ESC)
|
138 | 210 | {
|
139 |
| - editor.val(active.text()); |
| 211 | + template.off("blur"); |
140 | 212 |
|
141 |
| - e.preventDefault(); |
142 |
| - e.stopPropagation(); |
| 213 | + hideEditor(); |
| 214 | + //editor.val(active.text()); |
143 | 215 |
|
144 |
| - template.hide(); |
145 |
| - active.focus(); |
| 216 | + //template.hide(); |
| 217 | + //active.focus(); |
146 | 218 | }
|
147 | 219 | else if (e.which === TAB)
|
148 | 220 | {
|
149 |
| - active.focus(); |
| 221 | + if (doValidation()) |
| 222 | + { |
| 223 | + active.focus(); |
150 | 224 |
|
151 |
| - // Have to move here because dropdown eats it somehow if not |
152 |
| - var possibleMove = movement(active, e.shiftKey ? ARROW_LEFT : ARROW_RIGHT); |
| 225 | + // Have to move here because dropdown eats it somehow if not |
| 226 | + var possibleMove = movement(active, e.shiftKey ? ARROW_LEFT : ARROW_RIGHT); |
153 | 227 |
|
154 |
| - if (possibleMove.length > 0) |
155 |
| - { |
156 |
| - possibleMove.focus(); |
| 228 | + if (possibleMove.length > 0) |
| 229 | + { |
| 230 | + possibleMove.focus(); |
157 | 231 |
|
158 |
| - e.preventDefault(); |
159 |
| - e.stopPropagation(); |
| 232 | + e.preventDefault(); |
| 233 | + e.stopPropagation(); |
| 234 | + } |
160 | 235 | }
|
161 | 236 | }
|
162 | 237 | else if (this.selectionEnd - this.selectionStart === this.value.length ||
|
|
177 | 252 | if (template == editor)
|
178 | 253 | editor.width(active.width());
|
179 | 254 |
|
180 |
| - if (editor.valid()) |
181 |
| - { |
182 |
| - validator.settings.unhighlight(editor); |
183 |
| - |
184 |
| - // TODO: do we need this if app has proper bs highlight method? |
185 |
| - editor.parents(".form-group").removeClass("has-error"); |
186 |
| - } |
187 |
| - else |
188 |
| - { |
189 |
| - validator.settings.highlight(editor); |
190 |
| - |
191 |
| - // TODO: do we need this if app has proper bs highlight method? |
192 |
| - editor.parents(".form-group").addClass("has-error"); |
193 |
| - |
194 |
| - window.setTimeout(function () |
195 |
| - { |
196 |
| - $(template) |
197 |
| - .popover( |
198 |
| - { |
199 |
| - container: "body", |
200 |
| - content: function () { return validator.errorList[0].message; } |
201 |
| - }) |
202 |
| - .popover("show"); |
203 |
| - }, 100); |
204 |
| - } |
205 |
| - |
206 | 255 | if (select)
|
207 | 256 | {
|
208 | 257 | editor.select();
|
|
0 commit comments