Form Builder: form method somehow resets public property values

Hello, when setting properties in a Form Component in the mount method the changes don't get persisted so they return back to their default values. I only want to make the call to the AuthServiceInterface once because it also does a DB query. How can I achieve it to access values in the form method which have been set in the mount method? Thank you in advance.
class FinishUserDetailsPage extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

#[Locked]
public bool $showEmailField = false;
#[Locked]
public bool $showPasswordField = false;
#[Locked]
public bool $showUsernameField = false;

public function mount(AuthServiceInterface $authService): void
{
$this->form->fill();

$user = $authService->user();
$missing = $user->getMissingProperties();
$this->showEmailField = in_array(MissingUserPropertyEnum::EMAIL, $missing);
$this->showPasswordField = in_array(MissingUserPropertyEnum::PASSWORD, $missing);
$this->showUsernameField = in_array(MissingUserPropertyEnum::USERNAME, $missing);

// Here the values are true and set corrently
}

public function form(Form $form): Form
{
// Here are they all false again, why?
return $form
->schema([
TextInput::make('email')
->label('Email')
->hidden(!$this->showEmailField)
-
Actions::make([
Action::make('Anmelden')
->submit('login-form')
])->fullWidth()
])
->statePath('data');
}

public function render()
{
return view('livewire.finish-user-details-page');
}
}
class FinishUserDetailsPage extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

#[Locked]
public bool $showEmailField = false;
#[Locked]
public bool $showPasswordField = false;
#[Locked]
public bool $showUsernameField = false;

public function mount(AuthServiceInterface $authService): void
{
$this->form->fill();

$user = $authService->user();
$missing = $user->getMissingProperties();
$this->showEmailField = in_array(MissingUserPropertyEnum::EMAIL, $missing);
$this->showPasswordField = in_array(MissingUserPropertyEnum::PASSWORD, $missing);
$this->showUsernameField = in_array(MissingUserPropertyEnum::USERNAME, $missing);

// Here the values are true and set corrently
}

public function form(Form $form): Form
{
// Here are they all false again, why?
return $form
->schema([
TextInput::make('email')
->label('Email')
->hidden(!$this->showEmailField)
-
Actions::make([
Action::make('Anmelden')
->submit('login-form')
])->fullWidth()
])
->statePath('data');
}

public function render()
{
return view('livewire.finish-user-details-page');
}
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server