mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Bug fix for field validation on child forms (#3258)
* Bug fix for field validation on child forms - If a child form is launched which conatins numerical inputs, field validation fails - Not taking the "level" parameter into account when looking for the field * trim long description strings in modal forms
This commit is contained in:
parent
b2e31e3474
commit
8c6e3db774
@ -938,7 +938,7 @@ function getFormFieldElement(name, options) {
|
||||
/*
|
||||
* Check that a "numerical" input field has a valid number in it.
|
||||
* An invalid number is expunged at the client side by the getFormFieldValue() function,
|
||||
* which means that an empty string '' is sent to the server if the number is not valud.
|
||||
* which means that an empty string '' is sent to the server if the number is not valid.
|
||||
* This can result in confusing error messages displayed under the form field.
|
||||
*
|
||||
* So, we can invalid numbers and display errors *before* the form is submitted!
|
||||
@ -947,7 +947,8 @@ function validateFormField(name, options) {
|
||||
|
||||
if (getFormFieldElement(name, options)) {
|
||||
|
||||
var el = document.getElementById(`id_${name}`);
|
||||
var field_name = getFieldName(name, options);
|
||||
var el = document.getElementById(`id_${field_name}`);
|
||||
|
||||
if (el.validity.valueMissing) {
|
||||
// Accept empty strings (server will validate)
|
||||
|
@ -31,6 +31,18 @@
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Trim the supplied string to ensure the string length is limited to the provided value
|
||||
*/
|
||||
function trim(data, max_length=100) {
|
||||
if (data.length > max_length) {
|
||||
data = data.slice(0, max_length - 3) + '...';
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
// Should the ID be rendered for this string
|
||||
function renderId(title, pk, parameters={}) {
|
||||
|
||||
@ -55,7 +67,7 @@ function renderCompany(name, data, parameters={}, options={}) {
|
||||
|
||||
var html = select2Thumbnail(data.image);
|
||||
|
||||
html += `<span><b>${data.name}</b></span> - <i>${data.description}</i>`;
|
||||
html += `<span><b>${data.name}</b></span> - <i>${trim(data.description)}</i>`;
|
||||
|
||||
html += renderId('{% trans "Company ID" %}', data.pk, parameters);
|
||||
|
||||
@ -141,7 +153,7 @@ function renderStockLocation(name, data, parameters={}, options={}) {
|
||||
}
|
||||
|
||||
if (render_description && data.description) {
|
||||
html += ` - <i>${data.description}</i>`;
|
||||
html += ` - <i>${trim(data.description)}</i>`;
|
||||
}
|
||||
|
||||
html += renderId('{% trans "Location ID" %}', data.pk, parameters);
|
||||
@ -177,7 +189,7 @@ function renderPart(name, data, parameters={}, options={}) {
|
||||
html += ` <span>${data.full_name || data.name}</span>`;
|
||||
|
||||
if (data.description) {
|
||||
html += ` - <i><small>${data.description}</small></i>`;
|
||||
html += ` - <i><small>${trim(data.description)}</small></i>`;
|
||||
}
|
||||
|
||||
var stock_data = '';
|
||||
@ -256,7 +268,7 @@ function renderPurchaseOrder(name, data, parameters={}, options={}) {
|
||||
}
|
||||
|
||||
if (data.description) {
|
||||
html += ` - <em>${data.description}</em>`;
|
||||
html += ` - <em>${trim(data.description)}</em>`;
|
||||
}
|
||||
|
||||
html += renderId('{% trans "Order ID" %}', data.pk, parameters);
|
||||
@ -282,7 +294,7 @@ function renderSalesOrder(name, data, parameters={}, options={}) {
|
||||
}
|
||||
|
||||
if (data.description) {
|
||||
html += ` - <em>${data.description}</em>`;
|
||||
html += ` - <em>${trim(data.description)}</em>`;
|
||||
}
|
||||
|
||||
html += renderId('{% trans "Order ID" %}', data.pk, parameters);
|
||||
@ -319,7 +331,7 @@ function renderPartCategory(name, data, parameters={}, options={}) {
|
||||
var html = `<span>${level}${data.pathstring}</span>`;
|
||||
|
||||
if (data.description) {
|
||||
html += ` - <i>${data.description}</i>`;
|
||||
html += ` - <i>${trim(data.description)}</i>`;
|
||||
}
|
||||
|
||||
html += renderId('{% trans "Category ID" %}', data.pk, parameters);
|
||||
|
Loading…
Reference in New Issue
Block a user