mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Merge pull request #946 from SchrodingersGat/field-focus
Add "focus" option when displaying a modal form
This commit is contained in:
		| @@ -469,6 +469,9 @@ function openModal(options) { | |||||||
|  |  | ||||||
|     $(modal).on('shown.bs.modal', function() { |     $(modal).on('shown.bs.modal', function() { | ||||||
|         $(modal + ' .modal-form-content').scrollTop(0); |         $(modal + ' .modal-form-content').scrollTop(0); | ||||||
|  |         if (options.focus) { | ||||||
|  |             getFieldByName(modal, options.focus).focus(); | ||||||
|  |         } | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     // Prevent 'enter' key from submitting the form using the normal method |     // Prevent 'enter' key from submitting the form using the normal method | ||||||
| @@ -745,6 +748,7 @@ function launchModalForm(url, options = {}) { | |||||||
|      * after_render - Callback function to run after form is rendered |      * after_render - Callback function to run after form is rendered | ||||||
|      * secondary - List of secondary modals to attach |      * secondary - List of secondary modals to attach | ||||||
|      * callback - List of callback functions to attach to inputs |      * callback - List of callback functions to attach to inputs | ||||||
|  |      * focus - Select which field to focus on by default | ||||||
|      */ |      */ | ||||||
|  |  | ||||||
|     var modal = options.modal || '#modal-form'; |     var modal = options.modal || '#modal-form'; | ||||||
| @@ -763,6 +767,7 @@ function launchModalForm(url, options = {}) { | |||||||
|                 modal: modal, |                 modal: modal, | ||||||
|                 submit_text: submit_text, |                 submit_text: submit_text, | ||||||
|                 close_text: close_text, |                 close_text: close_text, | ||||||
|  |                 focus: options.focus | ||||||
|             }); |             }); | ||||||
|         }, |         }, | ||||||
|         success: function(response) { |         success: function(response) { | ||||||
|   | |||||||
| @@ -73,6 +73,7 @@ $("#add-test-result").click(function() { | |||||||
|                 stock_item: {{ item.id }}, |                 stock_item: {{ item.id }}, | ||||||
|             }, |             }, | ||||||
|             success: reloadTable, |             success: reloadTable, | ||||||
|  |             focus: 'test', | ||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
| }); | }); | ||||||
| @@ -89,6 +90,7 @@ $("#test-result-table").on('click', '.button-test-add', function() { | |||||||
|                 test: test_name |                 test: test_name | ||||||
|             }, |             }, | ||||||
|             success: reloadTable, |             success: reloadTable, | ||||||
|  |             focus: 'value', | ||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
| }); | }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user