Closed espensgr closed 6 months ago
There aren't any front-end facing events that will allow you to set the enabled state of a list, but we'll look at adding that support.
You can handle this yourself with PHP events in a module if you like:
use craft\events\ModelEvent;
use verbb\wishlist\elements\ListElement;
use yii\base\Event;
Event::on(ListElement::class, ListElement::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
$list = $event->sender;
$event->isValid = false;
if (Craft::$app->getRequest()->getParam('myParam')) {
$event->sender->enabled = false;
}
});
Where, you can check for the presence of a param you specify, to enable or disable the list when it's saved.
Nice! got it working with this
Event::on( ListElement::class, ListElement::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
$list = $event->sender;
$list->enabled = filter_var( Craft::$app->getRequest()->getParam( 'enabled' ) ?? false, FILTER_VALIDATE_BOOLEAN );
} );
But came across another "bug". After i have made a unabled list, i cannot delete it in frontend, i get this error:
error: "No list exists with the ID “888”."
I have the Manage Disabled Lists
setting turned on.
Fixed for the next release. To get this early, run composer require verbb/wishlist:"dev-craft-4 as 2.0.6
Nice, thanks!
Fixed in 2.0.7
Question
I'm trying to add the possibility to enable or disable a list when a user is creating it in the frontend. I have tried setting an
enabled
param in the ajax call. Is there a way i ca n do this, or do i have to add some custom stuff to thebeforeSaveList
event?Additional context
No response