Repository: internetarchive/openlibrary

Issue:
Re-enable autofill on add new book form
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->
At some point it seems auto-fill was disabled on the title field of the add new book form. It's quite handy when adding books from a series that have similar titles with small variations. Please re-enable.
### Evidence / Screenshot (if possible)

### Relevant url?
<!-- `https://openlibrary.org/...` -->
https://openlibrary.org/books/add

### Steps to Reproduce
<!-- What steps caused you to find the bug? -->
1. Go to ...the title field and start typing the title of a book already entered.
2. Do ...notice there is no auto-fill activated.

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual:no auto-fill
* Expected: auto-fill should recognise previously entered text and populate the field

### Details

- **Logged in (Y/N)?**
- **Browser type/version?**
- **Operating system?**
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->
@jimchamp 


Discussion:
@seabelis can I please take on this issue? Thank you!
@seabelis, so I understand, do you mean that the Browser's autofill feature (e.g. when google chrome suggests an autocomplete based on previous things you've entered) has been disabled for this page?

@XiyueJasmineZhang is this also your understanding of the problem? If so, can you share your proposed solution?

@cdrini tried to reproduce and is able to get browser autofill recommendations 🤔 
> @XiyueJasmineZhang is this also your understanding of the problem? If so, can you share your proposed solution?

Hi! XiyueJasmineZhang is my school github account but I submitted the PR under this account. My understanding was that of the fields that needs to be filled on the Add a Book page: https://openlibrary.org/books/add, the "Title" field doesn't give autofill recommendations.
@mekarpeles Yes. The publisher and date fields do auto-fill; the title field no longer auto-fills.
Some more details:
- Browser autofill for the title field is working as expected in Firefox
- Autofill is confirmed broken in Chrome and Brave browsers.
  - Suspect that the same is true for all Chromium-based browsers.
  - Unsure about Safari (@mekarpeles, could you check?)
- Changing the `name` attribute of the title input from `title` to `title-field` caused autofill to work again in Chrome.
  - Tested this by doing the following (with Chrome):
    1. Changed `name` attribute in my local instance.
    2. Added a book to my local instance.
    3. Loaded the production add book page.
    4. Modified the title input's `name` field using devtools.  Auto fill worked after the name was changed.

As a quick fix, we could change the name of this field.  Then, in the handler, set `i.title` equal to the new value [here](https://github.com/internetarchive/openlibrary/blob/e9993555c4a0f9687c83d2f81cc99548ac37d7bc/openlibrary/plugins/upstream/addbook.py#L229) (this will prevent having to make a ton of changes throughout the add book flow).  Whoever does this will have to make sure that the change doesn't break existing front-end validation on the title field.
I would like to on this issue assign me!
@shivam200446 are you still working on this?
@jimchamp Yes Sir, Working on it. Please elaborate more on the issue. I am just being confused with all above conversations.
Sure.  In the future, please ask questions if you have doubts.

1. Update the "Add book" template, [here](https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/books/add.html).  Autofill is not working for inputs that have `title` as the `name`, so these will need to be updated.  You can use `book_title` as the new `name`.
2. The POST handler for the add book form is [here](https://github.com/internetarchive/openlibrary/blob/bf28a890500529c502342d9ee2056ffaaa28a724/openlibrary/plugins/upstream/addbook.py#L219).  The expected form inputs and their default values are defined [here](https://github.com/internetarchive/openlibrary/blob/bf28a890500529c502342d9ee2056ffaaa28a724/openlibrary/plugins/upstream/addbook.py#L220-L228).  Add `book_title=""` to this object.  Then, set the value of `i.title` to `i.book_title`.

> Sure. In the future, please ask questions if you have doubts.
> 
> 1. Update the "Add book" template, [here](https://github.com/internetarchive/openlibrary/blob/master/openlibrary/templates/books/add.html).  Autofill is not working for inputs that have `title` as the `name`, so these will need to be updated.  You can use `book_title` as the new `name`.
> 2. The POST handler for the add book form is [here](https://github.com/internetarchive/openlibrary/blob/bf28a890500529c502342d9ee2056ffaaa28a724/openlibrary/plugins/upstream/addbook.py#L219).  The expected form inputs and their default values are defined [here](https://github.com/internetarchive/openlibrary/blob/bf28a890500529c502342d9ee2056ffaaa28a724/openlibrary/plugins/upstream/addbook.py#L220-L228).  Add `book_title=""` to this object.  Then, set the value of `i.title` to `i.book_title`.

Okay! Thank You so much

Resolving patch:
diff --git a/openlibrary/plugins/upstream/addbook.py b/openlibrary/plugins/upstream/addbook.py
--- a/openlibrary/plugins/upstream/addbook.py
+++ b/openlibrary/plugins/upstream/addbook.py
@@ -219,6 +219,7 @@ def has_permission(self) -> bool:
     def POST(self):
         i = web.input(
             title="",
+            book_title="",
             publisher="",
             publish_date="",
             id_name="",
@@ -226,6 +227,7 @@ def POST(self):
             web_book_url="",
             _test="false",
         )
+        i.title = i.book_title
 
         if spamcheck.is_spam(i, allow_privileged_edits=True):
             return render_template(


Test patch: