2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-02 05:26:45 +00:00

Updates for field rendering

This commit is contained in:
Oliver 2021-06-23 22:25:53 +10:00
parent c387e1a6fc
commit aa02377665

View File

@ -176,9 +176,14 @@ function constructCreateForm(url, fields, options={}) {
var html = '';
for (const key in fields) {
//console.log('field:', key);
html += constructField(key, fields[key], options);
var field = fields[key];
console.log(key, field.label, field.help_text);
var f = constructField(key, field, options);
html += f;
}
var modal = '#modal-form';
@ -220,7 +225,10 @@ function constructField(name, parameters, options={}) {
html += `<div class='controls'>`;
html += constructInput(name, parameters, options);
html += constructHelpText(name, parameters, options);
if (parameters.help_text) {
html += constructHelpText(name, parameters, options);
}
// TODO: Add the "error message"
@ -247,13 +255,16 @@ function constructLabel(name, parameters) {
label_classes += ' requiredField';
}
var html ='';
var html = `<label class='${label_classes}' for='id_${name}'>`;
html += `<label class='${label_classes}' for='id_${name}'>`;
html += name;
if (parameters.label) {
html += `${parameters.label}`;
} else {
html += `${name}`;
}
if (parameters.required) {
html =+ `<span class='asteriskField'>*</span>`;
html += `<span class='asteriskField'>*</span>`;
}
html += `</label>`;
@ -274,7 +285,15 @@ function constructInput(name, parameters, options={}) {
var html = '';
// TODO: Construct an input field based on the field type!
// TODO: Construct input differently depending on the input type!
html = `<input id='id_${name}' class='form-control'`;
if (parameters.required) {
html += " required=''";
}
html += '>';
return html;
}