F
Filament9mo ago
TK

How to prefill a TextInput on the create resource form?

So when I want to create a new user for example, I automatically want a TextInput to be filled with a certain value. And this should be visible to the users and not editable. I got everything, except for the part on how to fill that input text field. Anyone?
4 Replies
TK
TKOP9mo ago
Figured it out:
->afterStateHydrated(
function (TextInput $component, string $operation, $state, Set $set) {
if ('create' === $operation) {
$set('secret', Str::random(64));

return;
}

// ...
}
)
->afterStateHydrated(
function (TextInput $component, string $operation, $state, Set $set) {
if ('create' === $operation) {
$set('secret', Str::random(64));

return;
}

// ...
}
)
LeandroFerreira
LeandroFerreira9mo ago
->default(Str::random(64)) ?
TK
TKOP9mo ago
@Leandro Ferreira Problem was that I only needed to fill on the create page. LOL... you're right 🤦‍♂️ that should also work
LeandroFerreira
LeandroFerreira9mo ago
this only works on Create Pages

Did you find this page helpful?