It seems like you're facing an issue where the subdomain field is not being updated in the form when the name field changes. Since you've mentioned that the subdomain property is updated and shown below the field, it indicates that the Livewire component's property is being updated correctly, but the change is not reflected in the input field itself.
One potential issue could be related to Livewire's DOM-diffing engine. When Livewire updates the DOM, it tries to be smart about not updating parts of the DOM that it thinks haven't changed. If Livewire's DOM-diffing engine mistakenly thinks the input hasn't changed, it won't update it.
To ensure that the input field is updated when the subdomain property changes, you can use the wire:key directive to help Livewire identify that the input needs to be updated. Here's how you can modify your input field for the subdomain:
<div>
<label for="subdomain" class="frm-label">{{ __('Subdomain') }}</label>
<input wire:model="subdomain" wire:key="subdomain_field" type="text" class="frm-field">
@error('subdomain') <span class="error ct-red">{{ $message }}</span> @enderror
{{ $subdomain }} <!-- This is here just to display the subdomain, this shows perfectly -->
</div>
By adding wire:key="subdomain_field", you're giving a unique key to the input field, which should help Livewire recognize when it needs to be updated.
Additionally, ensure that you have imported the Str facade at the top of your Livewire component if you haven't already:
use Illuminate\Support\Str;
If the issue persists, you can also try to force a re-render of the component by calling $this->emitSelf('refreshComponent') after updating the subdomain property:
public function updated($propertyName)
{
$this->validateOnly($propertyName);
if ($propertyName == 'name') {
$this->subdomain = Str::slug($this->name);
$this->emitSelf('refreshComponent'); // Force a re-render of the component
}
}
This will emit an event that the component itself is listening for, and when it hears it, it will re-render, ensuring that the latest subdomain value is reflected in the input field.
Lastly, make sure that the name attribute of the subdomain input field is set correctly. In your provided code, both input fields have for="name" in their labels, which might be a typo. The subdomain input should have for="subdomain":
<label for="subdomain" class="frm-label">{{ __('Subdomain') }}</label>
Try these suggestions, and hopefully, your subdomain field will update as expected when the name field changes.