Просмотр исходного кода

Typical day - enter to create, up/down to travel

Vijayakrishnan 3 лет назад
Родитель
Сommit
ae9db32de5

+ 15 - 4
resources/views/app/patient/segment-templates/typical_day_lifestyle/edit.blade.php

@@ -155,6 +155,10 @@ if ($point->lastChildReview && $point->lastChildReview->data) {
             return tr;
         }
 
+        function createRowAfter(_tr) {
+            return newRow().insertAfter(_tr);
+        }
+
         function newRow() {
             return $('<tr><td class="align-middle text-center bg-light"><a href="#" class="delete-line"><i class="fa fa-trash-alt on-hover-opaque text-danger"></i></a></td>' +
                 '<td><textarea rows="1" key="S"></textarea></td>' +
@@ -162,6 +166,11 @@ if ($point->lastChildReview && $point->lastChildReview->data) {
                 '<td><textarea rows="1" key="P"></textarea></td></tr>');
         }
 
+        function createAndMoveToNextRowInput(_td) {
+            let tr = createRowAfter(_td.closest('tr'));
+            tr.find('td:eq(' + _td.index() + ') textarea').first().focus();
+        }
+
         function moveToNextRowInput(_td, _forceCreate = false) {
             let tr = _forceCreate ? getOrCreateRowAfter(_td.closest('tr')) : getRowAfter(_td.closest('tr'));
             if(tr.length) {
@@ -221,13 +230,15 @@ if ($point->lastChildReview && $point->lastChildReview->data) {
         parentSegment
             .off('keydown', '.stag-sheet textarea')
             .on('keydown', '.stag-sheet textarea', function(_e) {
-                console.log(_e.which);
-                console.log(this.selectionStart, this.selectionEnd);
-                console.log(this.value.length);
                 switch (_e.which) {
                     case 13: // ENTER: If shift NOT pressed, move to next row same column
                         if (!_e.shiftKey) {
-                            moveToNextRowInput($(this).closest('td'), $(this).closest('.stag-sheet').is('.allow-row-addition'));
+                            if($(this).closest('.stag-sheet').is('.allow-row-addition')) {
+                                createAndMoveToNextRowInput($(this).closest('td'), );
+                            }
+                            else {
+                                moveToNextRowInput($(this).closest('td'), false);
+                            }
                             return false;
                         }
                         break;