You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Like in #9, I too was searching for a solution to disable the event when editing a resource.
E.g. I have a news resource where the title generates a slug, but on edit this slug should not be changed. Now I could simply do an if/else if the request is an update or not, and just replace the Slug field with a disabled text field, but easier would be if I could just add a method like disableEvents($disable = true) with a default set to true.
I don't know what you (@drobee) think about this idea, but I did a quick edit and came with this solution.
src/Slug.php
// constructorpublic function __construct(...) {
...$this->disableEvents(false); // default to false...
}
// methodpublicfunctiondisableEvents(bool$disable = true) {
// I choose `meta` because somehow setOptions() sets a boolean to string "1" instead of `true`.return$this->withMeta(['disableEvents' => $disable]);
}
resources/js/components/Slug/FormField.vue
Changed the mounted method for a return if event should not be used.
mounted(){// return if event should be disabledif(this.field.disableEvents){return;}consteventType=this.field.options.event||'keyup';Nova.$on('field-update-'+eventType+'-'+this.field.name,({value})=>{this.generateSlug(value);},
I could make PR if you agree.
Another thing, I also added a delay for the generate slug request.
// return if event disabledif(this.field.disableEvents){return;}this.eventDelayTimeout=null;consteventType=this.field.options.event||'keyup';Nova.$on('field-update-'+eventType+'-'+this.field.name,({value})=>{// clear timeout if anyif(this.eventDelayTimeout!==null){clearTimeout(this.eventDelayTimeout);}// delay generation of slugthis.eventDelayTimeout=setTimeout((function(){this.generateSlug(value)}).bind(this),this.options.eventDelay);})
The text was updated successfully, but these errors were encountered:
@wize-wiz I'm sorry I've been neglecting this repo. I like your idea, it's simple yet effective. Would you still like to make a PR with this? I'd be grateful!
@wize-wiz I'm sorry I've been neglecting this repo. I like your idea, it's simple yet effective. Would you still like to make a PR with this? I'd be grateful!
Like in #9, I too was searching for a solution to disable the event when editing a resource.
E.g. I have a news resource where the title generates a slug, but on edit this slug should not be changed. Now I could simply do an
if/else
if the request is an update or not, and just replace theSlug
field with a disabled text field, but easier would be if I could just add a method likedisableEvents($disable = true)
with a default set to true.I don't know what you (@drobee) think about this idea, but I did a quick edit and came with this solution.
src/Slug.php
resources/js/components/Slug/FormField.vue
Changed the mounted method for a return if event should not be used.
I could make PR if you agree.
Another thing, I also added a delay for the generate slug request.
src/Slug.php
Mounted function with delay
The text was updated successfully, but these errors were encountered: