Git Product home page Git Product logo

Comments (5)

affektde avatar affektde commented on June 16, 2024

This would be interesting for dynamic input fields.

I try to loop over a collection of dynamic fields and have trouble with all the array keys.

I have something like this, to add fields dynamically.

/* addArtist($id, $participationId) */
$artists = $this->getState()['artists'];
$artists[] = [
    'id' => $id,
    'pivot' => [
        'participation_id' => $participationId,
    ]
];
$this->state['artists'] = $artists;
@foreach($this->state['artists'] as $artist)
    <li wire:key="artist{{ $artist['id'] }}">
        <input wire:model="state.artists.{{ $loop->index }}.id" />
    </li>
@endforeach

Like issue title says: "Adding custom function to the Step to manipulate the state"

How to manipulate the state within a public method in our WizardComponent.

Like @gozbert 's method removeFromCollection $this->state['locations'] will not reflect state on the frontend.

from livewire-wizard.

affektde avatar affektde commented on June 16, 2024

Ok I've got it working with:

    public function deleteArtist($index)
    {
        $artists = $this->getState()['artists'];
        unset($artists[$index]);
        $this->state['artists'] = array_values($artists);
        $this->putState(
            'artists',
            array_values($artists)
        );
    }

putState() needs to be called additionally. To be in sync with Livewire I think.

So @gozbert maybe this is working for you? Not tested, just my idea.

    public function removeFromCollection($key)
    {
        $this->state['locations']->pull($key);
        $this->putState(
            'locations',
            $this->state['locations']
        );
    }

from livewire-wizard.

gozbert avatar gozbert commented on June 16, 2024

@affektde if you add the function in the class which extends WizardComponent that function will be available on the view
Example
`
class Apply extends WizardComponent{

public function removeFromCollection($key)
{
    $this->state['locations']->pull($key);
    $this->putState(
        'locations',
        $this->state['locations']
    );
}

}
`
removeFromCollection() function will be available in every Steps view that you have so this will work if all of your function will be defined in the parent class of the Steps

What i need is the way that I can group the logic of the Step within the Step class without adding it to the parent that help in separation of concerns.

from livewire-wizard.

affektde avatar affektde commented on June 16, 2024

Ok now I understand @gozbert.

Step is not a Livewire component. It extends ViewComponent.

So we need somehow to hook into parent's WizardComponent Livewire.

I think this is a feature and we could develop a PR. Investigating the code design with those Step- classes and ViewComponent.

from livewire-wizard.

gozbert avatar gozbert commented on June 16, 2024

@affektde Yes, you are right

from livewire-wizard.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.