DocumentFilter for GuiTextFields

  • Would it be possible for RW GuiTextFields to have support for DocumentFilter and ofc extensions thereof?


    I would like to implement filters on my GuiTextFields to for example allow only numbers. I am sure something like this has already been implemented on the back-end as there exists a .setMaxCharacters() method which is a type of DocumentFilter


    Currently the only way to do this is proof the input once the TextField loses focus and reset it if it is wrong or highlight it red or something for the user to fix.

  • Well, adding support for DocumentFilters would be difficult, since the text field is only manipulated clientside. Having a DocumentFilter (serverside) in place would require the game to sync every input with the server (and probably wait for the server response), so this would result in additional traffic (and - apart from that - there might be a noticeable delay due to the ping) oO


    Do you just need it to allow certain characters only? In this case we could add a new method like "setAllowedCharacters()", preferably in combination with a regex. This way you can make sure the player can only enter numbers, for example :)

  • Do you just need it to allow certain characters only? In this case we could add a new method like "setAllowedCharacters()", preferably in combination with a regex. This way you can make sure the player can only enter numbers, for example

    As far as I can tell, I believe this would be the kind of cases @Minotorious might be referring to. The usual use cases are: integer numbers, decimal numbers, arbitrary texts.


    A selector INTEGER_ONLY (allowing just ,'+', '-', and [0-9]), FLOAT_ONLY (allowing ',' and/or '.' in addition), ANY (allowing any input) would already go ahead a long way.


    A regex would allows more flexibility like deciding the number of decimal figures and so on. Possibly allowing to specify a regex would already be enough, as far as I can tell. Of course, this can entirely happen client-side, once the server has sent it the regex.


    (Should RW go Unicode in the future, things would become much more murky, as in Unicode "digits", for instance, cover a lot of things more than simply [0-9], but we will cross that bridge when we'll get there, I suppose).

  • A regex would allows more flexibility like deciding the number of decimal figures and so on. Possibly allowing to specify a regex would already be enough, as far as I can tell. Of course, this can entirely happen client-side, once the server has sent it the regex.

    Do you just need it to allow certain characters only? In this case we could add a new method like "setAllowedCharacters()", preferably in combination with a regex. This way you can make sure the player can only enter numbers, for example

    Yes something like .setAllowedCharacters(regex) would be great and exactly what I would implement with the DocumentFIlter anyway (but simpler on my side, a bit more complex on your side to give us the Filter method complete and simple :D )


    also maybe a .setCharacterPattern(regex) method would be nice to have e.g. to allow a hex code in [#000000] pattern (^\\[#([A-Fa-f0-9]{6})\\]$) or a pattern of comma separated numbers of 3 digits each i.e. 001,002,003 (^[0-9]{3}[,][0-9]{3}[,][0-9]{3}$)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!