Improve form management when possible part matches are found

- Display the checkbox always
- Display a warning message above the form
This commit is contained in:
Oliver Walters 2019-05-11 18:07:37 +10:00
parent 7b4584ba2f
commit b3cca1d851
2 changed files with 7 additions and 3 deletions

View File

@ -5,7 +5,8 @@
{{ block.super }}
{% if matches %}
<b>Matching Parts</b>
<b>Possible Matching Parts</b>
<p>The new part may be a duplicate of these existing parts:</p>
<ul class='list-group'>
{% for match in matches %}
<li class='list-group-item list-group-item-condensed'>

View File

@ -191,13 +191,16 @@ class PartCreate(AjaxCreateView):
if len(matches) > 0:
context['matches'] = matches
# Enforce display of the checkbox
form.fields['confirm_creation'].widget = CheckboxInput()
# Check if the user has checked the 'confirm_creation' input
confirmed = str2bool(request.POST.get('confirm_creation', False))
if not confirmed:
form.fields['confirm_creation'].widget = CheckboxInput()
form.errors['confirm_creation'] = ['Possible matches exist - confirm creation of new part']
form.non_field_errors = 'Possible matches exist - confirm creation of new part'
form.pre_form_warning = 'Possible matches exist - confirm creation of new part'
valid = False
data = {