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
That sounds like what a password field would do. Is that what you're trying to accomplish?
Password fields also hash I believe. There is a PR for it... But there isn't one being done at present
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.okay thats nice, but how to hash the last 5 character?
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.
i want to mask the phone number
example:
original number : 123456789
expected outcome :
1234*****
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.?
the phone number textinput is disabled, but the user still can edit other textinput
it is just to minimize shoulder surfing
I think what you want is
->formatStateUsing(fn (string $state): string => substr($state, 0, -5).'***')
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.
wow this works...but when i save, it doesnt save as numbers
Yeah it should not save correctly, I though you want disabled() field, so you're not gonna save when edit..haha
And that’s my point. 🙂
so, what if i want to save it? is there any solution?
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.
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)i just tried disabled it, but it still failed to update because it is not a number
add
->dehyrdated(false)
? since this a disabled field, i assume you don't want to update it?turns out we can use
$mask->jsonOptions
include displayChar
thank you for those who help me 😄