web: fix part re-seletion
This commit is contained in:
parent
dd53223691
commit
a73628491c
|
@ -8,6 +8,8 @@
|
|||
var last_search = null;
|
||||
// the collection of parts
|
||||
var parts = null;
|
||||
// last selected part
|
||||
var part_id = null;
|
||||
// part field to populate
|
||||
const fields = ["name", "description", "details", "package", "manufacturer", "mpn", "family", "datasheet", "page", "location", "stock"];
|
||||
// URLs to set
|
||||
|
@ -41,10 +43,6 @@ function search()
|
|||
function results()
|
||||
{
|
||||
const results = document.getElementById('results');
|
||||
let part_id = -1;
|
||||
if (results.selectedIndex >= 0) {
|
||||
part_id = parseInt(results.options[results.selectedIndex].value);
|
||||
}
|
||||
results.innerHTML = null;
|
||||
for (const part of parts) {
|
||||
const option = document.createElement('option');
|
||||
|
@ -52,9 +50,9 @@ function results()
|
|||
option.innerHTML = part.name;
|
||||
if (part.description) {
|
||||
option.innerHTML += " (" + part.description + ")";
|
||||
if (part_id == part.id) {
|
||||
option.selected = "selected";
|
||||
}
|
||||
}
|
||||
if (part_id == part.id) {
|
||||
option.selected = "selected";
|
||||
}
|
||||
results.appendChild(option);
|
||||
}
|
||||
|
@ -84,9 +82,9 @@ function select_part()
|
|||
{
|
||||
const results = document.getElementById('results');
|
||||
if (results.selectedIndex >= 0) {
|
||||
let part_selected = parseInt(results.options[results.selectedIndex].value);
|
||||
part_id = parseInt(results.options[results.selectedIndex].value);
|
||||
for (const part of parts) {
|
||||
if (part.id == part_selected) {
|
||||
if (part.id == part_id) {
|
||||
//console.log(part);
|
||||
// populate part fields
|
||||
for (const field of fields) {
|
||||
|
|
Loading…
Reference in New Issue