Skip to content

(Fix) Don't reset DB IDs when .torrent is selected#5269

Open
Oha-you wants to merge 2 commits intoHDInnovations:developmentfrom
Oha-you:reset-ids-fix
Open

(Fix) Don't reset DB IDs when .torrent is selected#5269
Oha-you wants to merge 2 commits intoHDInnovations:developmentfrom
Oha-you:reset-ids-fix

Conversation

@Oha-you
Copy link
Contributor

@Oha-you Oha-you commented Feb 11, 2026

To reproduce:

  • Open Torrent Upload form
  • Set Title and some IDs: TMDB movie/TV ID, IMDB ID, MAL ID or TVDB ID
  • Pick a .torrent file
  • Observe that all IDs are reset

Note: this doesn't happen when you change the category first.
But it does happen if you set it on page load with torrents/create?category_id=2

I'm not sure why cat = $refs.catId.value was needed in @change originally for #2243
Because cat is assigned here anyway:

<section
class="upload panelV2"
x-data="{
cat: {{ old('category_id', (int) $category_id) }},
cats: JSON.parse(atob('{{ base64_encode(json_encode($categories)) }}')),

Values are reset because they listen to cat changes:

x-bind:value="cats[cat].type === 'movie' && tmdb_movie_exists ? '{{ old('tmdb_movie_id', $movieId) }}' : ''"

When you change the category from the dropdown list, IDs should reset - this is correct.
Also IDs are retrieved through TMDB API when the Title is not set and .torrent is selected.
But after you fill all the inputs in the upload form yourself, they shouldn't be touched.

@what-the-diff
Copy link

what-the-diff bot commented Feb 11, 2026

PR Summary

  • Removed value assignment in event handler
    Refactored the code to improve efficiency by eliminating the assignment of a value in an event handler for a file input.

@Oha-you
Copy link
Contributor Author

Oha-you commented Feb 11, 2026

Adding another commit here.
Condition in parenthesis always returns true because one of #auto_tmdb_movie or #auto_tmdb_tv values is always NULL depending on whether Movie or TV category is selected:

if (!name.value.trim() && (!tmdb_movie.value.trim() || !tmdb_tv.value.trim())) {

Introduced after the split happened: #4563
Originally this logic was added by me back in 2021: #1760

But I think just checking if the title is set should be enough. I doubt people set DB IDs first when they upload a torrent anyway.

id="torrent"
required
@change="uploadExtension.hook(); cat = $refs.catId.value"
@change="uploadExtension.hook()"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the reason this code is needed is because the uploadExtension.hook() changes #autocat's value, and alpine.js's x-model down below doesn't register this change and update its value, so it has to be done manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right. But what if we trigger the change event in JS instead of the template?
Please see the updated commit.
Tested it with Movies and TV category selected by default, then added a TV/Movie torrent.
@change event was triggered and DB ID inputs got updated.
This discussion helped: alpinejs/alpine#1388

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

Successfully merging this pull request may close these issues.

2 participants