mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-29 10:18:29 -04:00
- 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.
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
// Uses JQuery's autocomplete to make a suggestion in lieu of a
|
|
// preposterously long select dropdown. To implement add code to
|
|
// the view like this:
|
|
//
|
|
// = auto_suggest @resource, :auto_suggest_source
|
|
//
|
|
// You must also add a search method to the resource's controller.
|
|
|
|
jQuery(function () {
|
|
const el = $('.auto-suggest');
|
|
if (!el.length) return;
|
|
|
|
const id = $('.auto-suggest-id');
|
|
|
|
el.autocomplete({
|
|
minLength: 1,
|
|
source: el.attr('data-source-url'),
|
|
focus: function (event, ui) {
|
|
el.val(ui.item.name);
|
|
id.val(ui.item.id);
|
|
return false;
|
|
},
|
|
select: function (event, ui) {
|
|
el.val(ui.item.name);
|
|
id.val(ui.item.id);
|
|
return false;
|
|
},
|
|
response: function (event, ui) {
|
|
id.val('');
|
|
ui.content.forEach(function (item) {
|
|
if (item.name === el.val()) id.val(item.id);
|
|
});
|
|
}
|
|
});
|
|
|
|
const autocomplete = el.data('uiAutocomplete');
|
|
if (autocomplete) {
|
|
autocomplete._renderItem = function (ul, item) {
|
|
const label = item.matched_alternate_name
|
|
? `<a>${item.matched_alternate_name} <small class="text-muted">(${item.name})</small></a>`
|
|
: `<a>${item.name}</a>`;
|
|
return $('<li class="list-group-item"></li>')
|
|
.data('item.autocomplete', item)
|
|
.append(label)
|
|
.appendTo(ul);
|
|
};
|
|
}
|
|
});
|