Skip to content

Commit

Permalink
Remove uneditable flag name field from conditions
Browse files Browse the repository at this point in the history
This change hides the flag name field from condition creation and edit forms. The field was not editable by users, because the flag name is always provided.

The field had been rendering as blank, despite having the value filled in. This change moves it to a hidden field.
  • Loading branch information
willbarton committed Feb 25, 2020
1 parent 9383d87 commit da9a021
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion wagtailflags/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class FlagStateForm(forms.ModelForm):
label='Flag',
required=True,
disabled=True,
widget=forms.HiddenInput(),
)
condition = forms.ChoiceField(
label='Condition name',
label='Condition',
required=True
)
value = forms.CharField(
Expand Down
44 changes: 28 additions & 16 deletions wagtailflags/templates/wagtailflags/flags/edit_condition.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n feature_flags %}
{% block titletag %}{% if form.instance %}Edit {{ form.instance.condition }}{% else %}Create condition{% endif %}{% endblock %}
{% block titletag %}{% if form.instance %}Edit {{ form.instance.condition }} condition{% else %}Create condition{% endif %}{% endblock %}

{% block content %}
{% include "wagtailadmin/shared/header.html" with title=flag.name icon="tag" %}
Expand All @@ -18,23 +18,35 @@ <h2 class="nice-padding">
{% endif %}
{% csrf_token %}
<ul class="fields">
<li class="actions">
{% for field in form %}
{% if field.errors %}
<div class="help-block help-critical" style="margin-top:0;">
{{ field.errors }}

{% for field in form %}
<li {% if field.field.required %}class="required"{% endif %}>
{% if not field.is_hidden %}
<div class="field">
{{ field.label_tag }}

<div class="field-content">
<div class="input">
{{ field }}
</div>
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
</div>

{% if field.errors %}
<div class="help-block help-critical" style="margin-top:0;">
{{ field.errors }}
</div>
{% endif %}
</div>
{% else %}
{{ field }}
{% endif %}
<label>{{ field.label }}</label>
<div class="field-content">
<div class="input">
{{ field }}
<span></span>
</div>
<p class="help"></p>
</div>
{% endfor %}
</li>

</li>
{% endfor %}

<li class="actions">
<input class="button action-save button-longrunning" type="submit" value="Save condition" />
<a class="button bicolor icon icon-cog" href="{% url 'wagtailflags:flag_index' flag.name %}">Back to {{ flag.name }}</a>
Expand Down
2 changes: 1 addition & 1 deletion wagtailflags/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.test import TestCase, override_settings
from django.test import TestCase

from wagtail.tests.utils import WagtailTestUtils

Expand Down
3 changes: 1 addition & 2 deletions wagtailflags/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.http import Http404
from django.shortcuts import get_object_or_404, redirect, render, resolve_url
from django.shortcuts import get_object_or_404, redirect, render

from flags.models import FlagState
from flags.sources import get_flags
from flags.state import flag_enabled
from flags.templatetags.flags_debug import bool_enabled
from wagtailflags.forms import FlagStateForm, NewFlagForm

Expand Down

0 comments on commit da9a021

Please sign in to comment.