tomhatzer/nova-slug-field

Request: Remove TextWithSlug

dillingham opened this issue ยท 9 comments

Would it be possible to just use Slug and not TextWithSlug

ID::make()->sortable(),
Unique::make('Email'),
Slug::make('Slug')->from('Email'),

Hey @dillingham, thank you for your suggestion. I will have a look into it and test if it's possible without running into problems. :)

Sorry for beeing that quiet at the moment regarding this issue, but it's still on my list and I hopefully will find a good solution for it any time soon. :)

This would be a great addition and it would make more sense. It'll stop polluting your fields array..

Hey guys, very useful field type, unfortunately I can't use it because my case is similar to this one.

It will be much more effective, if we could specify a slug field, and specify from which field it should be slugified.

I have Place field, and I want to create a slug from address, so I would do something like

Place::make('address') ...
Slug::make('slug')->from('address')

Hey @benjaminhirsch :) any chance of this? or should I close?

Hey @dillingham, please don't, I still like the idea but still hadn't enough time since my last comment to get my head into it. I'm currently in the process of planning ๐Ÿค” something new which relates to Laravel and Nova which also involves the slug generation. This would then result in a major revamp of the current implementaion of my slug field package which could then potentially include your proposal. ๐Ÿ˜„

@benjaminhirsch how exciting! If there is any way to contribute or provide feedback Iโ€™m happy to help if I can.

I'd like to give a hand as well! Get a plan up and I'll be glad to help out.

You can make it one field by setting a watcher on Slug's component

Slug::make('Slug')->from('some-field-attribute')

    public function from($attribute)
    {
        $this->withMeta(['slug_field_attribute' => $attribute]);

        return $this;
    }
this.$parent.$children.forEach(component => {
    if(component.field !== undefined && component.field.attribute == this.field.slug_field_attribute) {
	    let attribute = 'value'
	    if(component.field.component === 'belongs-to-field') {
	        attribute = 'selectedResource';
	    }
	    component.$watch(attribute, (value) => {
	        this.slugValue = (value && attribute == 'selectedResource') ? value.value : value;
	    }, { immediate: true });
   }
})

I used a similar method in my https://github.com/dillingham/nova-ajax-select package and it worked nicely