Disable validation (when save as concept)

Hi all, I have a multi step form (4 steps total) I want to disable all validation on step 2,3,4 if user presses the "Save as concept" action. Below is my Action
private function getCreateConceptFormAction(): Action
{
return Action::make('concept')
->label(Helpers::translate('Save as concept'))
->color('info')
->submit(null)
->action(function ($livewire) {
$livewire->data['status'] = CarStatus::CONCEPT;
$this->create();
})
->keyBindings(['mod+s']);
}
private function getCreateConceptFormAction(): Action
{
return Action::make('concept')
->label(Helpers::translate('Save as concept'))
->color('info')
->submit(null)
->action(function ($livewire) {
$livewire->data['status'] = CarStatus::CONCEPT;
$this->create();
})
->keyBindings(['mod+s']);
}
As you can see i set a 'status' attribute. but the create process is the same as normal. I know the validation is somewhere in the below function and i think i need to overwrite this function to check the 'status' if i need to validate
$this->form->getState();
$this->form->getState();
i think i am overthinking this, so any help/insight would be helpful. Thanks.
Solution:
i solved it like this. create a function in the resource ```php private static function requiredConcept(): \Closure...
Jump to solution
3 Replies
toeknee
toeknee2w ago
usualyl that would be skippable but not sure if you can do it per step
Solution
Tieme
Tieme7d ago
i solved it like this. create a function in the resource
private static function requiredConcept(): \Closure
{
return fn ($livewire) => ! array_key_exists('status', $livewire->data) || $livewire->data['status'] != CarStatus::CONCEPT;
}
private static function requiredConcept(): \Closure
{
return fn ($livewire) => ! array_key_exists('status', $livewire->data) || $livewire->data['status'] != CarStatus::CONCEPT;
}
and call this function in required
Forms\Components\TextInput::make('price')
->prefixIcon('heroicon-o-currency-euro')
->formatStateUsing(fn ($state) => str_replace('.', ',', $state))
->mask(Support\RawJs::make('$money($input, \',\', \' \', 2)'))
->stripCharacters(' ')
->dehydrateStateUsing(fn ($state) => str_replace(',', '.', $state))
->columnSpan([
'default' => 1,
])
->required(self::requiredConcept()),
Forms\Components\TextInput::make('price')
->prefixIcon('heroicon-o-currency-euro')
->formatStateUsing(fn ($state) => str_replace('.', ',', $state))
->mask(Support\RawJs::make('$money($input, \',\', \' \', 2)'))
->stripCharacters(' ')
->dehydrateStateUsing(fn ($state) => str_replace(',', '.', $state))
->columnSpan([
'default' => 1,
])
->required(self::requiredConcept()),
and change the create action
$this->getCreateFormAction()
->label(Helpers::translate('Create Subscription'))
->keyBindings(false)
->color('success')
->submit(null)
->action(function ($livewire) {
$livewire->data['status'] = CarStatus::PENDING;
$this->create();
})
->requiresConfirmation()
$this->getCreateFormAction()
->label(Helpers::translate('Create Subscription'))
->keyBindings(false)
->color('success')
->submit(null)
->action(function ($livewire) {
$livewire->data['status'] = CarStatus::PENDING;
$this->create();
})
->requiresConfirmation()
If someone has a different more reliable approached i would love to here it.
toeknee
toeknee7d ago
Good stuff

Did you find this page helpful?