Comments (5)
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.
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.
@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.
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.
@affektde Yes, you are right
from livewire-wizard.
Related Issues (15)
- Validation rule unique HOT 1
- pass value to parent componenet HOT 1
- WireUI Security Patch
- I can't use livewire wire:click in my wizzard form
- Next Steps Depending on data entered on previous steps HOT 1
- Problems using Laravel 9.36.4 HOT 1
- Image upload (WithFileUploads) function don't work with livewire-wizard HOT 2
- Does not like long class names HOT 2
- Hook issue
- Cannot get value of fields in previous steps in the next step. HOT 1
- Call to undefined function Vildanbina\LivewireWizard\str() HOT 1
- Example source code HOT 1
- PHP 8.0 support HOT 1
- Have problem emitting from Javascript inside a step back to the component HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from livewire-wizard.