Commit 1d346076 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

using .form-control-placeholder for label field

parent 841bceb7
Pipeline #9207 passed with stages
in 12 minutes and 32 seconds
......@@ -2,24 +2,24 @@
iPPI-DB django forms
"""
from django.forms import ModelForm, modelformset_factory, modelform_factory, formset_factory, BaseFormSet, BaseModelFormSet
from django import forms
from django.db import models
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.forms import ModelForm, modelformset_factory, formset_factory, BaseFormSet
from .models import *
from .ws import pdb_entry_exists
""" Step 1 : IdForm """
class IdForm(ModelForm):
class Meta:
model = Bibliography
fields = ['source','id_source']
labels = {
"id_source": "ID"
}
widgets = {
'source' : forms.RadioSelect,
'id_source': forms.TextInput(attrs={'placeholder': 'ID'}),
'id_source': forms.TextInput(),
}
""" Step 2 : BibliographyForm """
......@@ -44,11 +44,21 @@ def validate_pdb_exists(value):
class PDBForm(forms.Form):
pdb_id = forms.CharField(label="PDB ID", max_length=4, widget=forms.TextInput(attrs={'placeholder': 'e.g 3u85', 'required': 'required', 'class':'form-control'}), required=True, validators=[
RegexValidator(
'^[0-9][a-zA-Z0-9]{3}$', message='PDB ID must be 1 numeric + 3 alphanumeric characters'),
validate_pdb_exists
])
pdb_id = forms.CharField(
label="PDB ID",
max_length=4,
widget=forms.TextInput(
attrs={
'placeholder': 'e.g 3u85',
'required': 'required',
}),
required=True,
validators=[
RegexValidator(
'^[0-9][a-zA-Z0-9]{3}$', message='PDB ID must be 1 numeric + 3 alphanumeric characters'),
validate_pdb_exists
])
class ProteinForm(ModelForm):
......
{% extends "add.html" %}
{% load i18n %}
{% load customtags %}
{% block form %}
<nav>
......@@ -37,8 +38,7 @@
{% endfor %}
{% else %}
<div class="input_field form-group">
{{form.pdb_id}}
<label for="id_PDBForm-pdb_id" class="form-control-placeholder">PDB ID</label>
{{form.pdb_id|bootstrap}}
</div>
{% endif %}
</table>
......
......@@ -20,14 +20,9 @@ def bootstrap(object):
if isinstance(object, BoundField):
field = object
attrs = {"class": "form-control" + (" is-invalid" if field.errors else "")}
try:
placeholder = field.field.widget.attrs.pop("placeholder")
except KeyError:
placeholder = None
ret = []
ret.append(field.as_widget(attrs=attrs))
if placeholder:
ret.append("""<label class="form-control-placeholder">%s</label>""" % placeholder)
ret.append("""<label class="form-control-placeholder">%s</label>""" % field.label)
if field.errors:
for e in field.errors:
ret.append("""<div class="invalid-feedback">%s</div>""" % e)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment