mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Fix for "focus" field in forms (#4644)
- Reimplements ability to auto-focus fields when launching modal forms - Can specify with the "focus" option - Otherwise, will focus on the first available field
This commit is contained in:
		| @@ -692,6 +692,21 @@ function constructFormBody(fields, options) { | |||||||
|  |  | ||||||
|     // Scroll to the top |     // Scroll to the top | ||||||
|     $(options.modal).find('.modal-form-content-wrapper').scrollTop(0); |     $(options.modal).find('.modal-form-content-wrapper').scrollTop(0); | ||||||
|  |  | ||||||
|  |     // Focus on a particular field | ||||||
|  |     let focus_field = options.focus; | ||||||
|  |  | ||||||
|  |     if (focus_field == null && field_names.length > 0) { | ||||||
|  |         // If no focus field is specified, focus on the first field | ||||||
|  |         focus_field = field_names[0]; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     let el = $(options.modal + ` #id_${focus_field}`); | ||||||
|  |  | ||||||
|  |     // Add a callback to focus on the first field | ||||||
|  |     $(options.modal).on('shown.bs.modal', function() { | ||||||
|  |         el.focus(); | ||||||
|  |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user