wireui / wireui

TallStack UI components
https://v1.wireui.dev
MIT License
1.37k stars 166 forks source link

Ajax Modal #42

Closed aliqasemzadeh closed 2 years ago

aliqasemzadeh commented 2 years ago

Hi I think we can have ajax modal

PH7-Jack commented 2 years ago

What do you think about modal ajax? Describe more about "ajax modal"

aliqasemzadeh commented 2 years ago

@PH7-Jack Hi For example load data from another component base on button click.

aliqasemzadeh commented 2 years ago

@PH7-Jack For Example:

        <x-modal blur fullscreen wire:model.defer="panelModal">
            <x-card fullscreen>
                <livewire:panel symbol="???" >
            </x-card>
        </x-modal>

While symbol will change base on onclick="$openModal('panelModal')"

PH7-Jack commented 2 years ago

When modal is opening, the livewire component receives a value?

aliqasemzadeh commented 2 years ago

@PH7-Jack Yes exactlly.

aliqasemzadeh commented 2 years ago

@PH7-Jack Can you guide me how to do it?

PH7-Jack commented 2 years ago

I believe this cannot be done, the variables passed in the livewire component are not reactive. But it is possible to do this using livewire events.

Create a listener into your component to receives and set the new value Before opening a modal, send an event with a new value to set

Ex:

Outside component
public function openModal() {
    $this->modal = true;
    $this->emit('set-value', $newValue);
}

Component Inside Modal
protected $listeners =['set-value' => 'setValue'];

public function setValue($value) {
    $this->myVar = $value;
}
trippo commented 2 years ago

I think this can be closed

PH7-Jack commented 2 years ago

I will go move it to one discussion, if the events solve the problem, I will mark it as complete