Files
growstuff/app/javascript/site/planting_alternate_name.js
T
Brenda Wallace e68c98fd38 Add JavaScript functionality for planting alternate names and tab navigation
- Implemented `planting_alternate_name.js` to load alternate names for crops in the planting form based on user input.
- Added `tab_navigation.js` to manage tab navigation and update the URL hash accordingly.

Update map rendering in member and place views

- Modified `_map.html.haml` to include a custom marker icon for member maps.
- Updated `index.html.haml` and `show.html.haml` to pass `places_map_data` to the map sections.

Refactor asset management in Rails application

- Removed Sprockets from the application configuration and adjusted asset paths.
- Updated asset precompilation settings and removed deprecated asset configurations from environment files.
- Added new build scripts for CSS and updated package dependencies in `package.json` for Bootstrap, Chart.js, and others.

Ensure React and CSS bundles are built before running tests

- Updated `react_bundle.rb` to check for the existence of both JavaScript and CSS bundles and build them if missing.
2026-10-20 23:55:33 +13:00

33 lines
1.1 KiB
JavaScript

// When a crop is chosen in the planting form, offer that crop's alternate names.
// Searching by an alternate name ("lauki") preselects it.
jQuery(function () {
const wrapper = $('#planting-alternate-name');
if (!wrapper.length) return;
const select = wrapper.find('select');
const cropId = $('#planting_crop_id');
const cropInput = $('#crop');
const load = function (id, typed) {
select.empty();
if (!id) return wrapper.addClass('d-none');
$.getJSON(wrapper.data('source-url'), { crop_id: id }, function (names) {
select.append($('<option>').text(cropInput.val()).val(''));
names.forEach(function (alt) {
const option = $('<option>').text(alt.name).val(alt.id);
if (typed && alt.name.toLowerCase() === typed.toLowerCase()) option.prop('selected', true);
select.append(option);
});
wrapper.toggleClass('d-none', names.length === 0);
});
};
cropInput.on('autocompleteselect', function (event, ui) {
const typed = ui.item.matched_alternate_name;
setTimeout(function () {
load(cropId.val(), typed);
}, 0);
});
});