tanthammar / tall-forms

Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.
https://github.com/tanthammar/tall-forms/wiki
MIT License
693 stars 86 forks source link

Notifications from session are empty #107

Closed swarakaka closed 2 years ago

swarakaka commented 2 years ago

If notifications are in session, they will be shown empty, and will be repeated four times.

$this->withSession()->notify('success','The form was saved successfully');

Bildschirmfoto 2022-02-04 um 11 44 29

tanthammar commented 2 years ago

May I see your full component please.

swarakaka commented 2 years ago

Yes, please :

<?php

namespace App\Http\Livewire\Forms\Companies;

use App\Models\Company;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Spatie\MediaLibraryPro\Http\Livewire\Concerns\WithMedia;
use Tanthammar\TallForms\Checkbox;
use Tanthammar\TallForms\ImageCropper;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\TallFormComponent;
use Tanthammar\TallFormsSponsors\Email;
use Tanthammar\TallFormsSponsors\Tel;

class CreateOrUpdateCompany extends TallFormComponent
{

    public Collection $breads;
    public string $backButton = 'companies';
    public string  $formTitle = '';
    public function mount(?Company $company)
    {
        $this->formTitle = $company->exists ?
            __('Edit :item ', ['item'=> $company->name])
            : __('Add :model ', ['model'=> __('Company')]);

        $this->breads = new Collection([
            ['text'=> __('Companies'), 'url'=> 'companies'],
            ['text'=> __($this->formTitle)],

        ]);
        //Gate::authorize()
        $this->mount_form($company); // $company from hereon, called $this->model
    }

    protected function formAttr(): array
    {
        return [
            'wrapWithView' => true,
            'showDelete' => false,
            'showReset' => !$this->model->exists,
        ];
    }

    // OPTIONAL methods, they already exist
    protected function onCreateModel($validated_data)
    {
        $this->model = Company::create($validated_data);
    }

    protected function onUpdateModel($validated_data)
    {
        $this->model->update($validated_data);
    }

    protected function onDeleteModel()
    {
        $this->defaultDelete();
    }

    protected function fields(): array
    {
        return [
            Checkbox::make(__('Allow Email Empty?'),'email_empty')
                ->default(false)
                ->rules('boolean')
                ->hideLabel(),

            Input::make(__('Name'), 'name')
                ->rules($this->model->exists
                    ? ['required', 'max:255', Rule::unique('companies','name')->ignore($this->model->id)]
                    :['required', 'max:255', Rule::unique('companies','name')])
                ->autocomplete("new-name")
                ->colspan(6),

            Input::make(__('Code'),'code')
                ->rules($this->model->exists
                    ?['required', 'max:255', Rule::unique('companies','code')->ignore($this->model->id)]
                    :['required', 'max:255', Rule::unique('companies','code')])
                ->autocomplete("new-code")
                ->colspan(6),

            Tel::make(__('Phone'),'phone')
                ->autocomplete("new-phone")
                ->rules(['required','digits_between:11,14'])
                ->colspan(6),

            Input::make(__('Phone owner'),'phone_owner')
                ->autocomplete("new-phone-owner")
                ->rules('required')
                ->colspan(6),

            Email::make(__('Email'),'email')
                ->rules('required_if:form_data.email_empty,false')
                ->autocomplete("new-email")
                ->colspan(6),

            Input::make(__('Address'),'address')
                ->autocomplete("new-address")
                ->rules('nullable')
                ->colspan(6),

        ];
    }

    protected function saveAndGoBackResponse()
    {
       $this->withSession()->notify('success','The form was saved successfully');
        return redirect()->route('companies');
    }
}
tanthammar commented 2 years ago

Thank you for reporting. Please upgrade to v8.2.4

swarakaka commented 2 years ago

It working perfect, thank you.