mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Refactor toot-toot
- Now can specify the "order" of fields
This commit is contained in:
		@@ -193,23 +193,39 @@ function constructCreateForm(url, fields, options={}) {
 | 
				
			|||||||
        ignored_fields.push('id');
 | 
					        ignored_fields.push('id');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const key in fields) {
 | 
					    // Construct an ordered list of field names
 | 
				
			||||||
 | 
					    var field_names = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Skip over fields
 | 
					    if (allowed_fields) {
 | 
				
			||||||
        if (allowed_fields && !allowed_fields.includes(key)) {
 | 
					        allowed_fields.forEach(function(name) {
 | 
				
			||||||
            continue;
 | 
					
 | 
				
			||||||
 | 
					            // Only push names which are actually in the set of fields
 | 
				
			||||||
 | 
					            if (name in fields) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (!ignored_fields.includes(name) && !field_names.includes(name)) {
 | 
				
			||||||
 | 
					                    field_names.push(name);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                console.log(`WARNING: '${name}' does not match a valid field name.`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        for (const name in fields) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!ignored_fields.includes(name) && !field_names.includes(name)) {
 | 
				
			||||||
 | 
					                field_names.push(name);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (ignored_fields &&  ignored_fields.includes(key)) {
 | 
					    field_names.forEach(function(name) {
 | 
				
			||||||
            continue;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var field = fields[key];
 | 
					        var field = fields[name];
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        var f = constructField(key, field, options);
 | 
					        var f = constructField(name, field, options);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        html += f;
 | 
					        html += f;
 | 
				
			||||||
    }
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var modal = '#modal-form';
 | 
					    var modal = '#modal-form';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user