-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PBNTR-667] Rails Typeahead Form Integration (#3893)
**What does this PR do?** A clear and concise description with your runway ticket url. [PBNTR-667](https://runway.powerhrg.com/backlog_items/PBNTR-667) addresses missing functionality from the playbook typeahead used within forms via the `form.typeahead` or `f.typeahead` construction. Specifically, this ticket is in response to an SLA request for accessible label, validation, and reset functionality. The results of my investigation were the following: - Label click-to-focus functionality was not present in the kit as currently structured. The added label functionality utilizes the recommended Rails form helper `@template.label(@object_name, name)`. It depends on a label's for property matching the text input's id. - Validation was not present in the kit as currently structured. Validation now works in two different ways. A boolean prop `required: true` taps into the browser's default validation properties. A user can also use the additional validation prop (in conjunction with `required: true` to add a custom validation message. - The resetting issue I believe is just a matter of implementation because the `is_multi: false` in the provided code snippet turns it a "react-rendered-rails" typeahead, not a "pure rails" one, and the reset functionality does not work as expected in the form context. I also cleaned up the [form kit page](https://playbook.powerapp.cloud/kits/form) some (having distinct labels between doc examples so that all label-clicks do not redirect to the "default' doc example). I would suggest a follow up story to add a "Form + Typeahead" doc example or clarifying text in the description on the Typeahead kit page as well to avoid the react-rendered-rails vs. rails issue. **Screenshots:** Screenshots to visualize your addition/change Clicking the label puts the focus on the input (see blue highlight around input box and cursor in input) <img width="1291" alt="label focus" src="https://github.com/user-attachments/assets/04688e62-f6b1-4ae3-ae71-2e4855760155"> Adding `required: true` provides validation (using the browser's generic "Please fill out this field" <img width="1289" alt="for PR typeahead required validation" src="https://github.com/user-attachments/assets/1adee33d-9019-448b-a978-30eee932b618"> Using a validation prop with a custom message will change the validation message (used along with `required: true`). <img width="1287" alt="for PR new custom validation error" src="https://github.com/user-attachments/assets/7f4899e2-b7ce-422b-b64c-8cb9d55b8a1d"> **How to test?** Steps to confirm the desired behavior: 1. Go to [form kit page](https://pr3893.playbook.beta.gm.powerapp.cloud/kits/form). A typeahead has been added as the first entry in the Default + Validation doc example. 2. When you click the "example typeahead" label, the focus should redirect to the typeahead. 3. When you've selected a user in the typeahead, scroll down to the bottom of the doc example and hit the "cancel" button. The form field for typeahead should reset (just like the rest of them do). 4. Without anything entered in the typeahead field, try to submit the form by pressing the "Save Example" button. The red error indicator should appear for the typeahead example (just like it does for the rest of them). 5. Clicking the labels for any other option in the Default + Validation doc ex should direct focus to the field directly below it, NOT to the corresponding field in the Default doc example like it does currently in [production](https://playbook.powerapp.cloud/kits/form#default-validation). #### Checklist: - [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [x] **DEPLOY** I have added the `milano` label to show I'm ready for a review. ~- [ ] **TESTS** I have added test coverage to my code.~
- Loading branch information
1 parent
713b220
commit 06f56c2
Showing
7 changed files
with
124 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
playbook/app/pb_kits/playbook/pb_form/docs/_form_form_with_loading.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters