nova-flexible-content icon indicating copy to clipboard operation
nova-flexible-content copied to clipboard

Error when using Slug field

Open dakala opened this issue 3 years ago • 7 comments

I've got this code:

Flexible::make('Practitioner types', 'practitioner_types')
            ->addLayout('Practitioner type', 'practitioner_type', [
                Text::make('Label', 'label'),
                Slug::make('Slug')->from('Label')
            ])
            ->collapsed()
            ->button('Add practitioner type'),

The slug field doesn't work and I get an error. See the screenshot please:

Screenshot_2022-05-13_at_07_54_34

What is the problem and how do I fix it please? Does it matter that I'm trying to do this with https://github.com/outl1ne/nova-settings ?

dakala avatar May 13 '22 07:05 dakala

Firstly, if you're specifying a column your from() should be referencing the column name, not the field label. Not an issue in this case as its just a capitalised version, but it wouldn't work if your column name was completely different.

Secondly, Nova 4 uses its dependsOn functionality for much of the underlying slug stuff, which isn't compatible with the current version of Flexible Content.

I have a pull request in to fix this functionality, however I am not an expert in Nova, Vue or Flexible content, although it seems to work fine from my testing. So you can either grab the version from my fork until its merged or wait for the maintainers to look it over and merge it.

Edit: Please note that you do not need to include the HasFlexibleDependsOn trait for the slug functionality to work, however you would for any other dependsOn stuff.

ianrobertsFF avatar May 13 '22 09:05 ianrobertsFF

@ianrobertsFF Thanks for this. I've just seen your PR. I'll try your fork later and let you know how I get on.

dakala avatar May 13 '22 10:05 dakala

Just FYI its not a maintained fork, just for the purposes of the PR

ianrobertsFF avatar May 13 '22 17:05 ianrobertsFF

Sure. I did a quick test of the fork with and without the nova-settings field but my slug field didn't work.

Perhaps it's me but I'm going to park this for now as I spent too much time on it before creating this issue. I'll come back to it later. Thanks for your help.

dakala avatar May 13 '22 18:05 dakala

Sure, pop back whenever you're ready.

I just forced a reinstall from my fork and retested it (none of us are infallible) and Its working on my end

A couple of things to note:

  • Make sure you're using the master from my fork, not the nova-4 branch. N4 was merged and is behind on commits.
  • make sure you're specifying dev-master as the version, not the 1.0.0 release, I haven't done any new releases on my fork
  • Slug fields by default in Nova don't update on an update page, only on create (See SlugField.vue:91), this would probably effect nova-settings as that's all updates I'm assuming?

You can override this behaviour by passing the following withMeta to your Slug field:

->withMeta([
    "updating"=>false
]),

I haven't yet integrated nova-settings with my Nova4 installation, but that's on my list for this weekend. Ill let you know how I get on.

ianrobertsFF avatar May 13 '22 19:05 ianrobertsFF

Secondly, Nova 4 uses its dependsOn functionality for much of the underlying slug stuff, which isn't compatible with the current version of Flexible Conten

This is incorrect, Slug uses frontend JS for everything not compatible to use dependsOn.

crynobone avatar Aug 03 '22 04:08 crynobone

Secondly, Nova 4 uses its dependsOn functionality for much of the underlying slug stuff, which isn't compatible with the current version of Flexible Conten

This is incorrect, Slug uses frontend JS for everything not compatible to use dependsOn.

You're right, I misspoke there, I should have said it uses the same underlying Form Events mixin which is the part in this instance that Flexible Content has compatibility issues with, due to its modification of attribute names.

Thanks for popping in 3 months later to clarify that minor point.

ianrobertsFF avatar Aug 03 '22 07:08 ianrobertsFF