add form validation on memory widget

This commit is contained in:
Alex Gittings 2022-03-14 16:42:27 +00:00
parent 5aee17e998
commit 5cb5033b1e
2 changed files with 6 additions and 2 deletions

View File

@ -177,8 +177,12 @@ class MemoryField(forms.MultiValueField):
def compress(cls, data): def compress(cls, data):
if data: if data:
size, unit = data size, unit = data
if size: if size and not unit:
raise forms.ValidationError("Memory unit cannot be blank.")
elif size and unit:
return size * cls.MULTIPLIERS[unit] return size * cls.MULTIPLIERS[unit]
elif not size and unit:
raise forms.ValidationError("Please enter a memory value when unit is selected.")
# #

View File

@ -112,7 +112,7 @@
{{ field }} {{ field }}
{% if bulk_nullable %} {% if bulk_nullable %}
<div class="form-check my-1"> <div class="form-check my-1">
<input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}_0" /> <input type="checkbox" class="form-check-input" name="_nullify" value="{{ field.name }}" />
<label class="form-check-label">Set Null</label> <label class="form-check-label">Set Null</label>
</div> </div>
{% endif %} {% endif %}