mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Custom rendering functions
This commit is contained in:
parent
341467ae8d
commit
4cf69a5a4c
@ -346,14 +346,19 @@ function initializeRelatedFields(modal, url, fields, options) {
|
|||||||
// Find the select element and attach a select2 to it
|
// Find the select element and attach a select2 to it
|
||||||
var select = $(modal).find(`#id_${name}`);
|
var select = $(modal).find(`#id_${name}`);
|
||||||
|
|
||||||
console.log('modal:', modal);
|
// TODO: Add 'placeholder' support for entry select2 fields
|
||||||
|
|
||||||
|
// TODO: Add 'pagination' support for the query
|
||||||
|
|
||||||
select.select2({
|
select.select2({
|
||||||
ajax: {
|
ajax: {
|
||||||
url: field.api_url,
|
url: field.api_url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
|
allowClear: !field.required, // Allow non required fields to be cleared
|
||||||
dropdownParent: $(modal),
|
dropdownParent: $(modal),
|
||||||
dropdownAutoWidth: false,
|
dropdownAutoWidth: false,
|
||||||
|
delay: 250,
|
||||||
|
cache: true,
|
||||||
// matcher: partialMatcher,
|
// matcher: partialMatcher,
|
||||||
data: function(params) {
|
data: function(params) {
|
||||||
// Re-format search term into InvenTree API style
|
// Re-format search term into InvenTree API style
|
||||||
@ -385,9 +390,14 @@ function initializeRelatedFields(modal, url, fields, options) {
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
},
|
},
|
||||||
|
},
|
||||||
templateResult: function(item, container) {
|
templateResult: function(item, container) {
|
||||||
|
console.log('templateResult:', item);
|
||||||
|
return item.text;
|
||||||
|
},
|
||||||
|
templateSelection: function(item, container) {
|
||||||
// Custom formatting for the item
|
// Custom formatting for the item
|
||||||
console.log("templateResult:", item);
|
console.log("templateSelection:", item);
|
||||||
if (field.model) {
|
if (field.model) {
|
||||||
// If the 'model' is specified, hand it off to the custom model render
|
// If the 'model' is specified, hand it off to the custom model render
|
||||||
return renderModelData(field.model, item, field, options);
|
return renderModelData(field.model, item, field, options);
|
||||||
@ -396,7 +406,6 @@ function initializeRelatedFields(modal, url, fields, options) {
|
|||||||
return item.text;
|
return item.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user