#TextInput, set default value (from backend)

15 messages · Page 1 of 1 (latest)

lapis coyote
#

Currently I have TextInput::make('user.name').
The name field of the user relation already have an value.
However it's not showing in the forms. So how can I make it show?

grizzled ingot
#

Please provide the code if you need more help

lapis coyote
# grizzled ingot Please provide the code if you need more help

My code was like this

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('user.name')

I tried your way

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->relationship('user')

Neither way worked

#

More help please

timid wyvern
#

I think, it will work in select?

Forms\Component\Select::make('name')
->relationship('User', 'name')
#

don't forget to add ->preload() so it will automatically list all user upon loading of the page

lapis coyote
#

Yes, your way works for select.
But how about for TextInput?

timid wyvern
#

it won't work in TextInput since it is text input.

lapis coyote
timid wyvern
#

wdym?

#

you want to retrieve the name from user? then set it to current form?

last kayak
carmine crescent
#

Your code should actually do it. But you need to check if the relationships on the model is set.

lapis coyote
#

Thank you