mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-03 13:58:47 +00:00
Render simple choice fields with select2
This commit is contained in:
parent
770cd9a12d
commit
54731746d8
@ -2,6 +2,7 @@
|
|||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* This file contains code for rendering (and managing) HTML forms
|
* This file contains code for rendering (and managing) HTML forms
|
||||||
* which are served via the django-drf API.
|
* which are served via the django-drf API.
|
||||||
*
|
*
|
||||||
@ -17,6 +18,7 @@
|
|||||||
* - Read / write status
|
* - Read / write status
|
||||||
* - Field required status
|
* - Field required status
|
||||||
* - min_value / max_value
|
* - min_value / max_value
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -785,17 +787,16 @@ function initializeRelatedFields(fields, options) {
|
|||||||
|
|
||||||
var field = fields[name] || null;
|
var field = fields[name] || null;
|
||||||
|
|
||||||
if (!field || field.type != 'related field') continue;
|
if (!field || field.hidden) continue;
|
||||||
|
|
||||||
if (field.hidden) continue;
|
|
||||||
|
|
||||||
if (!field.api_url) {
|
|
||||||
// TODO: Provide manual api_url option?
|
|
||||||
console.log(`Related field '${name}' missing 'api_url' parameter.`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
switch (field.type) {
|
||||||
|
case 'related field':
|
||||||
initializeRelatedField(name, field, options);
|
initializeRelatedField(name, field, options);
|
||||||
|
break;
|
||||||
|
case 'choice':
|
||||||
|
initializeChoiceField(name, field, options);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,6 +835,12 @@ function addSecondaryModal(name, field, options) {
|
|||||||
*/
|
*/
|
||||||
function initializeRelatedField(name, field, options) {
|
function initializeRelatedField(name, field, options) {
|
||||||
|
|
||||||
|
if (!field.api_url) {
|
||||||
|
// TODO: Provide manual api_url option?
|
||||||
|
console.log(`Related field '${name}' missing 'api_url' parameter.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the select element and attach a select2 to it
|
// Find the select element and attach a select2 to it
|
||||||
var select = $(options.modal).find(`#id_${name}`);
|
var select = $(options.modal).find(`#id_${name}`);
|
||||||
|
|
||||||
@ -995,6 +1002,17 @@ function initializeRelatedField(name, field, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function initializeChoiceField(name, field, options) {
|
||||||
|
|
||||||
|
var select = $(options.modal).find(`#id_${name}`);
|
||||||
|
|
||||||
|
select.select2({
|
||||||
|
dropdownAutoWidth: false,
|
||||||
|
dropdownParent: $(options.modal),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Render a 'no results' element
|
// Render a 'no results' element
|
||||||
function searching() {
|
function searching() {
|
||||||
return `<span>{% trans "Searching" %}...</span>`;
|
return `<span>{% trans "Searching" %}...</span>`;
|
||||||
@ -1343,8 +1361,6 @@ function constructChoiceInput(name, parameters, options) {
|
|||||||
|
|
||||||
var choices = parameters.choices || [];
|
var choices = parameters.choices || [];
|
||||||
|
|
||||||
// TODO: Select the selected value!
|
|
||||||
|
|
||||||
for (var idx = 0; idx < choices.length; idx++) {
|
for (var idx = 0; idx < choices.length; idx++) {
|
||||||
|
|
||||||
var choice = choices[idx];
|
var choice = choices[idx];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user