Created
July 19, 2025 17:39
-
-
Save rorens05/15a736c73e6280c2af503dd4f22b5fe5 to your computer and use it in GitHub Desktop.
Select 2 Stimulus Controller
This file contains hidden or 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
def provinces | |
data = Province | |
.ransack(name_cont: params[:q], region_id_eq: params[:region_id]) | |
.result | |
.limit(20) | |
render json: data.map { |item| { id: item.id, text: item.name } } | |
end |
This file contains hidden or 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
f.input :province, | |
as: :select, | |
input_html: { | |
data: { | |
controller: 'select2', | |
url: provinces_select_address_index_path, | |
'dependent-input-id': 'job_seeker_personal_information_region_id', | |
'dependent-param-name': 'region_id' | |
} | |
}, | |
collection: f.object.province.present? ? [f.object.province] : [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment