Jump to content

Use "number" input type for all integer fields in the PW admin


Robin S
 Share

Recommended Posts

I find that the "number" input type is an enhancement for fields that are only to contain whole numbers. It lets you use the spinner arrows at the right of the input or your keyboard arrow keys to increment the number up and down, and it avoids invalid decimal or text values from being entered into the field.

The PW admin uses number inputs for InputfieldInteger in some places but these are not used consistently and I regularly find myself trying and failing to increment values in an integer field that isn't using input type number. For example, in the "Rows" setting of a textarea field.

image.png.9b3fe2b370b096cade977616c1d98012.png

With a simple hook in /site/ready.php you can ensure that all integer fields use input type number:

$wire->addHookAfter('InputfieldInteger::renderReadyHook', function(HookEvent $event) {
	$event->return->type = 'number';
});

image.png.0d5f6bdb24b5506c6827d055bdd9a37d.png

 

  • Like 6
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...