is there a way to hide value in textinput by replacing value to *?

tried using the code below, but what should i put in pattern so that i could replace my original value to *? ->mask(fn (Forms\Components\TextInput\Mask $mask) => $mask ->pattern('') ) *edited: how to mask the last 5 character?
19 Replies
DrByte
DrByte14mo ago
That sounds like what a password field would do. Is that what you're trying to accomplish?
toeknee
toeknee14mo ago
Password fields also hash I believe. There is a PR for it... But there isn't one being done at present
DrByte
DrByte14mo ago
Good point. But, if you use ->type('password') instead of ->password() then you only set the HTML field attribute, without invoking Filament's hashing. I recall having to do something like that in another context. I don't have access to that code right now to go see what exactly I did though, lol.
filament_newbie
filament_newbieOP14mo ago
okay thats nice, but how to hash the last 5 character?
awcodes
awcodes14mo ago
What are you trying to do? Going from a mask to hashing a character set is not a normal thing. Please explain exactly what you are trying to do in non technical words. Eli5 it for me.
filament_newbie
filament_newbieOP14mo ago
i want to mask the phone number example: original number : 123456789 expected outcome : 1234*****
awcodes
awcodes14mo ago
But why.? If someone is authorized to edit it what is the point of obfuscating it? If they are authorized to edit it then why does it matter if they can see it.?
filament_newbie
filament_newbieOP14mo ago
the phone number textinput is disabled, but the user still can edit other textinput it is just to minimize shoulder surfing
Vp
Vp14mo ago
I think what you want is ->formatStateUsing(fn (string $state): string => substr($state, 0, -5).'***')
awcodes
awcodes14mo ago
Totally valid, but the problem there is dehydrating any changes so it isn’t masked when it’s saved to the db. But that is dependent on the use case.
filament_newbie
filament_newbieOP14mo ago
wow this works...but when i save, it doesnt save as numbers
Vp
Vp14mo ago
Yeah it should not save correctly, I though you want disabled() field, so you're not gonna save when edit..haha
awcodes
awcodes14mo ago
And that’s my point. 🙂
filament_newbie
filament_newbieOP14mo ago
so, what if i want to save it? is there any solution?
awcodes
awcodes14mo ago
An actual mask would be the only way to do it, but I’m not sure how to achieve an editable partial mask. Sorry. I’m sure it’s possible. Just not sure how to do it. Definitely not an out of the box thing.
Vp
Vp14mo ago
If it's disabled() field then it will not submit iirc. but you can use mutateFormDataBeforeFill() and replace the actual data with database value (if it does)
filament_newbie
filament_newbieOP14mo ago
i just tried disabled it, but it still failed to update because it is not a number
ZedoX
ZedoX14mo ago
add ->dehyrdated(false)? since this a disabled field, i assume you don't want to update it?
filament_newbie
filament_newbieOP14mo ago
turns out we can use $mask->jsonOptions include displayChar thank you for those who help me 😄
Want results from more Discord servers?
Add your server