diff --git a/InvenTree/templates/js/forms.js b/InvenTree/templates/js/forms.js index c741530523..7668fc05ed 100644 --- a/InvenTree/templates/js/forms.js +++ b/InvenTree/templates/js/forms.js @@ -217,7 +217,13 @@ function constructField(name, parameters, options={}) { var field_name = `id_${name}`; - var html = `
`; + var form_classes = 'form-group'; + + if (parameters.errors) { + form_classes += ' has-error'; + } + + var html = `
`; // Add a label html += constructLabel(name, parameters); @@ -225,13 +231,15 @@ function constructField(name, parameters, options={}) { html += `
`; html += constructInput(name, parameters, options); - + + if (parameters.errors) { + html += constructErrorMessage(name, parameters, options); + } + if (parameters.help_text) { html += constructHelpText(name, parameters, options); } - - // TODO: Add the "error message" - + html += `
`; // controls html += `
`; // form-group @@ -293,6 +301,8 @@ function constructInput(name, parameters, options={}) { html += " required=''"; } + html += ` placeholder="${parameters.placeholder || ''}"`; + html += '>'; return html; @@ -312,4 +322,33 @@ function constructHelpText(name, parameters, options={}) { var html = `
${parameters.help_text}
`; return html; +} + + +/* + * Construct an 'error message' div for the field + * + * arguments: + * - name: The name of the field + * - parameters: Field parameters returned by the OPTIONS method + */ +function constructErrorMessage(name, parameters, options={}) { + + var errors_html = ''; + + for (var idx = 0; idx < parameters.errors.length; idx++) { + + var err = parameters.errors[idx]; + + var html = ''; + + html += ``; + html += `${err}`; + html += ``; + + errors_html += html; + + } + + return errors_html; } \ No newline at end of file