Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Button #9

Open
cgarofalo opened this issue Aug 2, 2019 · 5 comments
Open

Generate Button #9

cgarofalo opened this issue Aug 2, 2019 · 5 comments

Comments

@cgarofalo
Copy link

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!

@wize-wiz
Copy link
Contributor

@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
Copy link
Contributor

@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.

@spekulatius
Copy link

spekulatius commented Jan 14, 2020

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 ?

@bernhardh
Copy link

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.

@spekulatius
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants