Jump to content

Extended integer field


teppo
 Share

Recommended Posts

So, I've been wondering (since this evening) if it would be possible to extend default integer field with two features / settings:

The main reason I'm suggesting this is that I've banged my head on a wall that is int(11) couple of times now and I'd very much prefer having better option than using a text field in those cases. Sure, a text field combined with proper filtering + sanitizing usually gets the job done just fine, but at the same time it feels more than a bit hackish and introduces yet another chance for human error to thrive.

Signed / unsigned part would be just a "nice to have" extra feature and probably wouldn't be of use for most PW users, but from a DB design point of view it would make a heck of a lot of sense; if I'm only interested in positive integers (which is almost always the case, by the way) why would I allow negative input and especially if I'm not allowing it at UI level then why should it be allowed at DB level? Oh, and that extra space "unsigned" results in is a nice bonus :)

I do know that this would be quite easy to put together as a new fieldtype, but I wanted to try tossing it around here first, just in case that someone else would feel that it'd be worth adding to built-in field. Obvious downside of this whole idea is that changing settings like these would require changes to DB schema, so what I'm asking for may not be possible at all -- in which case I'm probably just going to put together a new "big integer" field..

  • Like 1
Link to comment
Share on other sites

It is possible, and I've thought we'd eventually do this but it just hasn't come up before now. Fieldtypes can modify their own schema by keeping a schema version in their field settings. Both the comments, and files/images fieldtypes do this in 2.3 to support new features. So will take the same route with the integer type to support the things you've outlined. Should be able to visit this soon after wrapping up the new version. Btw, the way I've handled this in the past is to create the field in PW, then go into phpmyadmin to tweak the details. But I'd rather people be able to do this all in PW. Still if it's something you need today, it's generally safe to modify a field_* table schema to suit a specific need.

  • Like 1
Link to comment
Share on other sites

Ryan, thanks for your answer. For now I'm going to go with what you suggested and alter db schema to my needs, but it's good to hear that this not only is possible but quite likely will be doable in the near future :)

Link to comment
Share on other sites

  • 1 year later...

Anyone knows what the status of this is? Just wondering because i wanted to add a int 3963252157 to a integer field, but because its not unsigned the number is to large and triggers a "out of range" error.

Could be i missed it but i couldnt find the settings of the integer field, or is there perhaps a different fieldtype i need to install?

Running PW 2.4.1 (latest dev branche)

Link to comment
Share on other sites

Maybe because integer is int and not bigint or tinyint?

Edit: Sorry, wasn't reading all thread, hehe. Agree it would be nice feature to have more options to integer, although not often needed that's maybe why it's still missing?. Also there's a min-max setting though uncommented in integer module. 

Link to comment
Share on other sites

  • 1 year later...

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

×
×
  • Create New...