Repository: bookwyrm-social/bookwyrm

Issue:
Save-button seems unresponsive when adding a book in Firefox for Android when no sort title is given
**Describe the bug**
When I try to add a new book or a new edition of a book in Firefox for Android and I add no sort title, the save-button seems unresponsive. Nothing happens when I press the button.

**To Reproduce**
Steps to reproduce the behavior:
1. Open Firefox on an Android device.
1. Go to "Add Book" (https://bookwyrm.social/create-book on the instance I use.)
1. Add a title, don't add a sort title
1. Scroll down to the save-button
1. Press save-button
1. Nothing happens

**Expected behavior**
When I go through the steps above on my laptop, the browser scrolls to the missing field and shows a hint which data is missing. I would expect the same behavior in Firefox for Android.

**Instance**
https://bookwyrm.social/

---
**Smartphone:**
    - Device: Fairphone 4
    - OS: Android 12
    - Browser: Firefox
    - Version 116.0



Discussion:
Thank you! I think the system should probably auto-populate the sort title when none is provided

Resolving patch:
diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py
--- a/bookwyrm/models/book.py
+++ b/bookwyrm/models/book.py
@@ -217,6 +217,13 @@ def get_remote_id(self):
         """editions and works both use "book" instead of model_name"""
         return f"https://{DOMAIN}/book/{self.id}"
 
+    def guess_sort_title(self):
+        """Get a best-guess sort title for the current book"""
+        articles = chain(
+            *(LANGUAGE_ARTICLES.get(language, ()) for language in tuple(self.languages))
+        )
+        return re.sub(f'^{" |^".join(articles)} ', "", str(self.title).lower())
+
     def __repr__(self):
         # pylint: disable=consider-using-f-string
         return "<{} key={!r} title={!r}>".format(
@@ -374,16 +381,7 @@ def save(self, *args: Any, **kwargs: Any) -> None:
 
         # Create sort title by removing articles from title
         if self.sort_title in [None, ""]:
-            if self.sort_title in [None, ""]:
-                articles = chain(
-                    *(
-                        LANGUAGE_ARTICLES.get(language, ())
-                        for language in tuple(self.languages)
-                    )
-                )
-                self.sort_title = re.sub(
-                    f'^{" |^".join(articles)} ', "", str(self.title).lower()
-                )
+            self.sort_title = self.guess_sort_title()
 
         return super().save(*args, **kwargs)
 
diff --git a/bookwyrm/views/books/edit_book.py b/bookwyrm/views/books/edit_book.py
--- a/bookwyrm/views/books/edit_book.py
+++ b/bookwyrm/views/books/edit_book.py
@@ -32,6 +32,9 @@ class EditBook(View):
     def get(self, request, book_id):
         """info about a book"""
         book = get_edition(book_id)
+        # This doesn't update the sort title, just pre-populates it in the form
+        if book.sort_title in ["", None]:
+            book.sort_title = book.guess_sort_title()
         if not book.description:
             book.description = book.parent_work.description
         data = {"book": book, "form": forms.EditionForm(instance=book)}
@@ -40,6 +43,7 @@ def get(self, request, book_id):
     def post(self, request, book_id):
         """edit a book cool"""
         book = get_object_or_404(models.Edition, id=book_id)
+
         form = forms.EditionForm(request.POST, request.FILES, instance=book)
 
         data = {"book": book, "form": form}


Test patch: