nova-sluggable icon indicating copy to clipboard operation
nova-sluggable copied to clipboard

Generate Button

Open cgarofalo opened this issue 5 years ago • 5 comments

Hi there,

Would it be possible to add an option where the slug is generated by clicking a button instead of keyup and blur? I'd only like to generate the slug if it's required. As is, the slug will change when the title field is updated. I don't really want the slug automatically change if I'm editing vs. creating.

Thanks!

cgarofalo avatar Aug 02 '19 21:08 cgarofalo

@cgarofalo Only if I understood it correctly.

You could distinguish update and create with the given $request and readonly method.

Slug::make(...)->readOnly($request->isUpdateOrUpdateAttachedRequest() ? true : false)

This will prevent the slug from being changed in edit mode and the slug being changable in any other mode.

wize-wiz avatar Oct 10 '19 15:10 wize-wiz

@cgarofalo Ah sorry, this behaviour isn't cross-browser. I create a new issue and PR if the author is ok with an added feature.

wize-wiz avatar Oct 10 '19 21:10 wize-wiz

That would make the package much more usable. Slug are often in URL segments and these shouldn't accidentally change - for a number of reasons (SEO, bookmarks, etc.).

Do you think you could look at this @drobee ?

spekulatius avatar Jan 14 '20 11:01 spekulatius

As a workaround to prevent changes on update, you could do it like so:

SluggableText::make()
   ->slug($request->isUpdateOrUpdateAttachedRequest() ? 'DONOTUPDATE' : 'Slug');

It checks if its an update request and if yes, it tries to update the not existing 'DONOTUPDATE' field. Otherwise (on create) it uses the correct field label Slug (or whatever you named it).

This is dirty, I know, but it works until @drobee fixes this issue.

bernhardh avatar Mar 25 '20 12:03 bernhardh

That's a good idea. Thanks for the suggestion @bernhardh

spekulatius avatar Mar 25 '20 17:03 spekulatius