wire/templates-admin/scripts/inputfields.js
/***********************************************************************************************
 * Adjustments for unintended actions, like hitting enter in a text field in a multi-button form
 * 
 */
Adjustments for unintended actions, like hitting enter in a text field in a multi-button form
Adjustments for unintended actions like hitting enter in a text field in a multi - button form
function InputfieldIntentions() {
	var $ = jQuery;
	$(".InputfieldForm").each(function() {
		var $form = $(this); 
		var numButtons = null;
		var $input = null;
		$form.submit(function() {
			if(!$(this).hasClass('nosubmit')) return;
			if(!$input) return;
			var $buttons = null;
			var $inputfields = $input.closest(".Inputfields"); 
			do {
				$buttons = $inputfields.find("input[type=submit]:visible, button[type=submit]:visible"); 
				if($buttons.length > 0) break;
				$inputfields = $inputfields.parent().closest(".Inputfields"); 
			} while($inputfields.length > 0);
			if($buttons.length > 0) {
				var $button = $buttons.eq(0);
				$('html, body').animate({ scrollTop: $button.offset().top }, 'fast');
				$button.focus();
			}
			return false;
		}).on("focus", "input, select", function() {
			if(numButtons === null) numButtons = $form.find("input[type=submit], button[type=submit]").length;
			if(numButtons < 2) return;
			$form.addClass('nosubmit');
			$input = $(this); 
		}).on("blur", "input, select", function() {
			$form.removeClass('nosubmit');
		}); 
	});
	if($("input[type=file]").length) {
		$(document).on({
			dragover: function() {
				if($(this).is("input[type=file]")) return;
				return false;
			},
			drop: function() {
				if($(this).is("input[type=file]")) return;
				return false;
			}
		});
	}
}
function InputfieldIntentions ( ) { var $ = jQuery ; $ ( ".InputfieldForm" ) . each ( function ( ) { var $form = $ ( this ) ; var numButtons = null ; var $input = null ; $form . submit ( function ( ) { if ( ! $ ( this ) . hasClass ( 'nosubmit' ) ) return ; if ( ! $input ) return ; var $buttons = null ; var $inputfields = $input . closest ( ".Inputfields" ) ; do { $buttons = $inputfields . find ( "input[type=submit]:visible, button[type=submit]:visible" ) ; if ( $buttons . length > 0 ) break ; $inputfields = $inputfields . parent ( ) . closest ( ".Inputfields" ) ; } while ( $inputfields . length > 0 ) ; if ( $buttons . length > 0 ) { var $button = $buttons . eq ( 0 ) ; $ ( 'html, body' ) . animate ( { scrollTop : $button . offset ( ) . top } , 'fast' ) ; $button . focus ( ) ; } return false ; } ) . on ( "focus" , "input, select" , function ( ) { if ( numButtons === null ) numButtons = $form . find ( "input[type=submit], button[type=submit]" ) . length ; if ( numButtons < 2 ) return ; $form . addClass ( 'nosubmit' ) ; $input = $ ( this ) ; } ) . on ( "blur" , "input, select" , function ( ) { $form . removeClass ( 'nosubmit' ) ; } ) ; } ) ; if ( $ ( "input[type=file]" ) . length ) { $ ( document ) . on ( { dragover : function ( ) { if ( $ ( this ) . is ( "input[type=file]" ) ) return ; return false ; } , drop : function ( ) { if ( $ ( this ) . is ( "input[type=file]" ) ) return ; return false ; } } ) ; } }
Adjustments for unintended actions, like hitting enter in a text field in a multi-button form
Adjustments for unintended actions like hitting enter in a text field in a multi - button form
// adjustments for unintended actions, like hitting enter in a text field in a multi-button form // find nearest visible submit button // scroll to first found button and focus it // if more than 1 submit button, prevent form submission while text input or select is focused // allow submissions again once they are out of the field // prevent dragged in files from loading in the browser (does not interfere with other drag/drop handlers)