tomhatzer / nova-slug-field

Slug field for Laravel Nova

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slug not updating while typing after updating to v1.2.1

nlenkowski opened this issue · comments

Hello, possible bug report here.

I just updated nova-slug-field to v1.2.1 and my slug field has stopped updating when typing into the source field. This occurs when creating a new record or updating an existing record. I'm not seeing any errors in the console and downgrading to v1.1.1 resolves the issue. Perhaps I'm doing something wrong or the configuration has changed with the new version.

Here's the relevant fields from my Nova resource:

TextWithSlug::make('Name')
    ->slug('Slug')
    ->rules('required')
    ->sortable(),

Slug::make('Slug')
    ->rules('required', 'alpha_dash')
    ->creationRules('unique:properties,slug')
    ->updateRules('unique:properties,slug,{{resourceId}}')
    ->sortable()
    ->hideFromIndex(),

My project is on Laravel 5.8.14 with all dependencies updated:

"require": {
  "php": "^7.2",
  "benjaminhirsch/nova-slug-field": "^1.1",
  "fideloper/proxy": "^4.0",
  "gregoriohc/laravel-nova-theme-responsive": "^0.6.1",
  "intervention/image": "^2.4",
  "laravel/framework": "^5.8",
  "laravel/nova": "^2.0",
  "laravel/telescope": "^2.0",
  "laravel/tinker": "^1.0"
},
"require-dev": {
  "beyondcode/laravel-dump-server": "^1.0",
  "filp/whoops": "^2.0",
  "fzaninotto/faker": "^1.4",
  "mockery/mockery": "^1.0",
  "nunomaduro/collision": "^3.0",
  "phpunit/phpunit": "^8.0"
},

@benjaminhirsch Thanks for looking into this, and for nova-slug-field. Its super useful and should be merged into Nova if you ask me!

Hey @nlenkowski, thank you for reporting this issue. This is something I noticed by myself today too. I will bring a fix really soon. :)

1.2.2 is out now 😄

Sorry, but I'm still seeing the same issue on v1.2.2. Perhaps there is something wonky with my config?

Seems fine to me. I'll take a look into it.

@nlenkowski Version 1.2.3 is out and should fix this problem finally. I was able to reproduce your problem locally, but In another Nova installation Version 1.2.2 was working fine. In version 1.2.3 I've now changed the way I recognize if creation oder edit mode is active. Hope this will work now as expected. 😄

@benjaminhirsch Thanks so much for digging into this, it's much appreciated. I've been able to get everything working with v1.2.3, but a change to the README example may also be needed.

To test I disabled all of my fields and added the following in my Nova resource, straight from the README. This surprisingly did not work!

TextWithSlug::make('Name')
    ->slug('Slug'),

Slug::make('Slug'),

I then made the following change:

TextWithSlug::make('Name')
    ->slug('slug'),

Note, the s in ('slug'). Changing it from upper to lower case resolved issue.

I'm not sure if its specific to my config, but the README example may be incorrect.

Thanks @nlenkowski!

After upgrading, I had a problem where slugs were not automatically filled in when writing in the name field.

Change this:
TextWithSlug::make('Name')->slug('Alias')
to this
TextWithSlug::make('Name')->slug('alias')

fixed it!

We should definitely put a note that is case-sensitive. Any reason this changed though?

Yes, with 1.2.1 I changed the identifier to attribute instead of the acutal name. The attribute is normally genererated from the name which get's internally casted to lowercase.

I will put a note in the release notes, thanks! 👍