From 5aae4545d5636356af8e20efbab7e8124034caba Mon Sep 17 00:00:00 2001 From: "ulsyemr@gmail.com" Date: Wed, 12 Aug 2026 23:25:16 +0300 Subject: [PATCH 1/3] Add a disabled state that locks the field and omits it from the form --- README.md | 47 +++++++++++ .../advanced_select/advanced_select.css | 10 +++ .../advanced_select_controller.js | 42 +++++++++- app/views/advanced_select/_select.html.erb | 13 +-- lib/advanced_select/class_map.rb | 1 + lib/advanced_select/helper.rb | 3 +- .../install/templates/advanced_select.css | 10 +++ .../templates/advanced_select_controller.js | 42 +++++++++- .../advanced_select_examples/show.html.erb | 13 +++ .../advanced_select_interaction_test.rb | 82 +++++++++++++++++++ 10 files changed, 255 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c719da4..62d2139 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ AdvancedSelect is a small Rails engine for rendering an advanced select input wi - [Custom Option Content](#custom-option-content) - [Option Contract](#option-contract) - [Events](#events) +- [Disabled State](#disabled-state) - [API Reference](#api-reference) - [Local Development](#local-development) - [i18n](#i18n) @@ -791,6 +792,49 @@ const select = application.getControllerForElementAndIdentifier(element, "advanc select.currentValue // => ["3", "7"] ``` +### Disabled State + +Pass `disabled: true` to lock a field. It still renders its current selection — +the point is to show the value, not to hide it — but it cannot be opened, +searched, or cleared, and its value is **left out of the form**: + +```erb +<%= advanced_select_tag( + "record[item_id]", + id: "record_item_id", + selected: selected_option, + options: options, + placeholder: "Choose an item", + disabled: true +) %> +``` + +This matches a native `