F
Filamentβ€’16mo ago
Altffenser

Text to case...

Hello devs! I am looking for a function that convert text to uppercase (or title case) in TextInput or TextArea, you know any implementation to do it? I usually do it with javascript but I can't find a way to inject JS into the component.
6 Replies
cheesegrits
cheesegritsβ€’16mo ago
Do you want to do it on submit, or "live" in the form when the blur out of the input?
Altffenser
AltffenserOPβ€’16mo ago
Interesting question. I would like it to be live. πŸ˜„
cheesegrits
cheesegritsβ€’16mo ago
You could try something like ...
TextInput::make('foo')
->lazy()
->afterStateUpdated(fn (string $state, Form\Set $set) => $set('foo', strtoupper($state)),
TextInput::make('foo')
->lazy()
->afterStateUpdated(fn (string $state, Form\Set $set) => $set('foo', strtoupper($state)),
Altffenser
AltffenserOPβ€’16mo ago
Working but not as expected. 😦
DrByte
DrByteβ€’16mo ago
How "not expected"?
Altffenser
AltffenserOPβ€’16mo ago
https://stackoverflow.com/a/45067218 I found this answer, check the behavior with Hugh Messenger's solution.
Stack Overflow
Change Input to Upper Case
JS: <script type="text/css"> $(function() { $('#upper').keyup(function() { this.value = this.value.toUpperCase(); }); }); </script> HTML <div id="search"> ...

Did you find this page helpful?