Is it possible to pre-populate this form with some data?
I have a custom widget, with a heading defined like so:
This widget lives on a Company details page, what I would like to do when adding the contact, is to be able to pre-populate some of the information that will come from the company, such as the address.
Is this possible with my current implementation or would I have to change to work?
19 Replies
Try the above
I will give that a go, thank you.
Sadly, that does not work and gives the following error:
Call to a member function mountUsing() on string
Likely due to getDefaultName() returning string|null
I can change it to this:
Which mounts the form again but does not fill the first_name inputAhh sorry just seen it more so. If you adjust the create page, you should be about to user
I'll have a look, thank you.
Sorry, which create page, for the resource I want to add? It doesn't have a create page as I am using modals, so I have, list,view and edit
So that says the button for add contact goes to a url?
Are you making it url button but rending the action within it?
Personally, I’ll add the action as per the docs on the livewire component. Then render the action opposed to calling a view button then you can use fill using
I cannot remember where I got this syntax from, I think I got it from another help thread before as I wanted to navigate and action from a different view. Do you mind linking to the part of the docs you mean?
I am unsure where the documentation for this lives if someone is able to help point me in the right direction that would be great.
Thank you, I will try and move to providing an action this way with the data required. Not sure how I got to the syntax above but I am certain it came from here somewhere 😹
Ah, so I found the original thread where I picked up / discussed the syntax I shared above: https://discord.com/channels/883083792112300104/1204006622750318632
However, I also noted that this is similar to an issue I was having and Dan was helping me with. So moving more inline to what you have suggested, and Dan previously, I now have this code:
and
However I am getting an error around relationships:
Here is the error:
So it is complaining about null being received but I am unsure where this value comes from.
Should I be defining a relationship?
You issue is coming from the form. Can you provide the contract resource form? I suspect you are specifying it in here.
How do you mean sorry? The public method in my ContactResource?
->form(fn ($form) => ContactResource::form($form))
you are using the form, so it's about where it is coming from.
we need the form that renders
I think I follow.
$form
is a required param so I needs to get the form that the ContactResource uses.
The syntax came from Dan in another thread but I guess I can just build a form in there?Try building the basic's of the form as a test
I am having a really hard time getting anything to work at the moment. Any
new Form
I try and create requires livewire
I've come back to it after a bit of time off and just struggling to get my brain into gear.Action::make()->form() requires an array schema? so:
->form([
TextInput::make('name')
])
gotcha, sorry, I did that previously but it didn't show, I think I must have been missing something else.
that is however now rendering a form.
And is it filled?
adding this to the action:
Does indeed fill the the name field. So I just have to change it to the fields I want to populate and we should be good!
Thank you so much!
Welcomes