agiliq / django-parsley Goto Github PK
View Code? Open in Web Editor NEWClient side form validations for Django - Using parsley.js
Home Page: http://agiliq.com/demo/parsley/
License: BSD 3-Clause "New" or "Revised" License
Client side form validations for Django - Using parsley.js
Home Page: http://agiliq.com/demo/parsley/
License: BSD 3-Clause "New" or "Revised" License
I'm using django-pipeline so I copied the parsley js file to my app's static folder.
I have it setup like so:
PIPELINE_JS = {
'main': {
'source_filenames': (
'javascript/vendor/bootstrap-3.0.3.min.js',
'javascript/vendor/parsley.min.js',
),
'output_filename': 'javascript/main.js',
},
}
I am also loading jquery 1.10.2
through a CDN. jquery is being loaded in the <head>
of the page and the rest is being loaded at the bottom.
I'm using a model form like so:
@parsleyfy
class FooForm(ModelForm):
class Meta:
model = Foo
It is being set with form_class
inside of a CreateView
view.
I have the templates setup like so:
<form parsley-validate method="post">{% csrf_token %}
{% for field in form %}
{{ field.errors }}
{{ field.label_tag }} {{ field }}
{% endfor %}
<input type="submit" value="Add this foo"/></a>
</form>
But when I load the page there are no parsley attributes in the html, no errors in the console and all of the static assets are reachable. What's going on?
There are no docs on localization, and it's possible: download locale files , include them in html, add js:
window.ParsleyValidator.setLocale('{{ STRIPPED_LOCALE }}');
I think that documentaion is needed. Maybe locale files should be included too.
pip install django-parsley failed when pip version > 1.4
Downloading/unpacking django-parsley
Could not find a version that satisfies the requirement django-parsley (from versions: 0.0.2a0, 0.0.1a0)
Cleaning up...
No distributions matching the version for django-parsley
Could you update a new package in pypi ?
http://stackoverflow.com/questions/14739809/django-overwriting-modelform-save-causes-recursion
This needs to be addressed.
I can't have Django 1.8.3 if I have django-parsley in my requirements file. Is this as intended? If not, perhaps changing
install_requires=["Django>=1.3,<=1.8"]
to
install_requires=["Django>=1.3,<1.9"]
or
install_requires=["Django>=1.3,<=1.8.6"] # 1.8.6 is the latest 1.8 as of now
in setup.py would work? As it is, I can't have it my requirements file which makes automated deployments annoying. There are some import security updates in 1.8.2 and 1.8.3.
Actually, I can have it in the requirements file if I move django-parsley to the top, although Django 1.8 is unnecessarily installed first.
Hi, I'm just doing research on JS libraries to use for form validation in Django and obviously this project does just that :)
I'd love to check out the demo you have but the link to it is returning a 404: https://agiliq.com/demo/parsley/
Is it still online somewhere? Cheers.
Hi! First, thanks for making django-parsley! It seems that version 0.7 of django-parsley was released (https://github.com/agiliq/Django-parsley/releases/tag/v0.7), but it isn't available on pypi (pip install django-parsley==0.7
fails): https://pypi.org/project/django-parsley/#history. Would it be possible to get this version uploaded to pypi?
Thanks!
I'm trying to get parsley working with a 3-widget phone number field similar to the one shown in the MultiValueField example in the documentation.
Setting min_length
and max_length
of 3, 3, and 4 for each field respectively (for US phone numbers) doesn't result in data-minlength and data-maxlength being specified because parsley is only run on the top level fields (not the ones inside the multi-value field).
Django 1.9 is already released and trying to install Django-parsely would make it rollback to 1.8
In version 0.7 it won't show a custom error message declared like this:
from django.utils.translation import ugettext_lazy as _
...
self.fields['num'] = forms.CharField(
required=False, max_length=15, label=_("Kennzeichnung"),
widget=forms.TextInput(attrs={'class': 'form-control', 'pattern': '[0-9]{15,15}',
'title': _('Eine Kennzeichnung besteht nur aus Zahlen!'),
# fixing django-parsley bug 'parsley-error-message' (missing data):
'data-parsley-error-message':_('Eine Chipnummer besteht nur aus Zahlen!')
}
)
)
Solution is to add data-parsley-error-message="message" instead of parsley-error-message="message" to the html code.
We would like to use parsley to do client side form validation in our django admin interface. This works quite well. However, we have to click to submit button before the validations are runned. This is probably because the trigger is set to false (https://github.com/agiliq/Django-parsley/blob/master/parsley/static/parsley/js/parsley.js#L131). Is it possible to change this trigger to 'change' in some way, without modifying the static files?
Would be really great to hear from you
Hi, great module!
I was wondering if I could use this to validate client-side if one of two fields from the form were used (only one of both is required).
So let's say you can either upload a file or a provide a link, so I want to validate that only one of these two is filled.
Thanks!
While running python manage.py shell
and doing from parsley.tests.forms import TextForm
, I get ImportError. So six
should be added in requirements.
There have been a lot of changes to django-parsley since the current version on PyPI. Maybe it's time for a new release? Maybe 0.0.3 or 0.1.0?
The current runtests.py script does not work for Django 1.7 (or 1.8?) anymore, and while at it I've wondered what's your opinion on using pytest for tests?
The docs say "If you're using parsley.js < 1.2, make sure to set the parsley_namespace Meta attribute to data"
Parsley.js 2 uses data-parsley-, it's parsley.js 1 that uses parsley-
This is extremely confusing. The doc needs to be updated ASAP.
Hi,
When using a DecimalField() in form like:
amount = forms.DecimalField(max_digits=12, decimal_places=2, required=True, max_value=999999999999.99, min_value=-999999999999.99)
I get this as attributes in the input text, which doesn't work with parlseyjs:
data-parsley-max="1e+12" data-parsley-min="-1e+12"
Hi, this app looks great. I'd like to use it with a ModelForm. Could you provide an example? Thanks!!
Hi, thanks a lot for this amazing plugin!
What would be the best way to have custom validation based on the back end using parsley remote?
Thanks!
I've got a form field which parsley validates correctly but returns "this field is required." I'm attempting to return my own custom error message for this field and I have this in my Meta class in the forms.py:
parsley_extras = {
'category': {
'error-message': 'Category is required.',
},
}
Can someone tell me what I'm doing wrong?
Here is my code:
from parsley.decorators import parsleyfy
def get_state_choices():
#return tuple of states
@parsleyfy
class NewForm(ModelForm):
state = forms.ChoiceField(widget = forms.Select( choices = get_state_choices() ) )
class Meta:
model = MyModel
fields('state',)
def __init__(self, *args, **kwargs):
super(NewForm, self).__init__(*args, **kwargs)
self.fields['state'] = forms.ChoiceField(
choices=get_state_choices() )
What I need is to populate the state field from database as a drop down. It was working fine until I put @parsleyfy decorator. Now the function which return the tuple of states is not getting called.
I'm using django-parsley in a lot of places on a site of mine and for whatever reason I just noticed that on one form (the rest seem to be fine) I can click submit on a blank form and parsley displays the errors as it should, but then my form continues to submit anyway. Any ideas why this may happen? I've checked all my parsley settings, etc., and it doesn't appear that I'm doing anything wrong but maybe i'm overlooking something. Here's my code:
from parsley.decorators import parsleyfy
@parsleyfy
class PostSubmitForm(forms.ModelForm):
summary = forms.CharField(max_length=10000, required=False, widget=forms.Textarea, error_messages={'max_length': 'The body of a text post can have at most 10000 characters (it has %(show_value)d).'})
def is_valid(self):
form = super(PostSubmitForm, self).is_valid()
return form
class Meta:
model = Post
fields = ('title', 'summary', 'category', 'pin', 'url')
<form data-parsley-validate action="/submit/" method="post" id="new-post" enctype="multipart/form-data">
{% csrf_token %}
<fieldset>
<input type="hidden" value="{{ selected_img }}" class="selected-img-src" name="selected-img-src" size="100" />
<div class="form-field url-field">
<p class="url-helper">Sharing a link? Enter the URL (then hit the tab button or click out) and we'll try to return some images so you can pick one that's relevent for your post.</p>
<label for="link-url">URL</label>
<input type="text" name="url" value="{% if form.url.value %}{{ form.url.value }}{% endif %}" class="" id="post-url" placeholder="http://www.domain.com" />
<div class="searching"></div>
<div class="url-error"></div>
<div id="images" class="review-images"></div>
</div>
<div class="form-field">
<label for="id_category">Category <span class="required">*</span></label>
{{ form.category }}
{% if form.category.errors %}<span class="parsley-required">Category is required</span>{% endif %}
</div>
<div class="form-field">
<label for="title">Title <span class="required">*</span></label>
<input type="text" id="title" name="title" value="{% if form.title.value %}{{ form.title.value }}{% endif %}" size="100" data-parsley-required="true" data-parsley-required-message="Please enter a title for your post." />
{% if form.title.errors %}<span class="parsley-required">Title is required</span>{% endif %}
</div>
<div class="form-field">
<label for="summary">Body</label>
<textarea name="summary" id="summary" cols="30" rows="10" maxlength="10000">{% if form.summary.value %}{{ form.summary.value }}{% endif %}</textarea>
</div>
{% if user.is_superuser %}
<div class="form-field">
<label for="username_list">Select an existing user</label>
<select name="username_list">
<option disabled selected>-- None --</option>
{% for user in my_users %}
<option value="{{ user.username }}" >{{ user.username }}</option>
{% endfor %}
</select>
</div>
<div class="form-field">
<label for="username">or Enter a new username</label>
<input type="text" name="username" />
<label for="mugshot">New User Mugshot URL when entered a new username</label>
<input type="text" name="mugshot" />
</div>
<div class="form-field pin-submit">
<label for="id_pin">{{ form.pin }}Pin?</label>
</div>
{% endif %}
<div class="form-field form-actions">
<input type="submit" value="Submit Post" />
</div>
</fieldset>
</form>
If the error messages for a specific validator (e.g. required
errors) is overridden in Django, this same custom error message should probably also appear in parsleyjs.
Changing error messages will become even easier in Django 1.6 with a new error_messages
Meta property.
Thoughts on this idea?
This request seems to fix this issue ... though it seems it must not be updated at pip.
When attempting to install via pip,
(asdf_virtual)#prggmr… (django-parsley)$:→ pip install django-parsley
Downloading/unpacking django-parsley
Running setup.py egg_info for package django-parsley
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/Users/prggmr/Lab/Envs/asdf_virtual/build/django-parsley/setup.py", line 116, in <module>
long_description=read("README.md"),
File "/Users/prggmr/Lab/Envs/asdf_virtual/build/django-parsley/setup.py", line 11, in read
return open(os.path.join(os.path.dirname(__file__), fname)).read()
IOError: [Errno 2] No such file or directory: '/Users/prggmr/Lab/Envs/asdf_virtual/build/django-parsley/README.md'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/Users/prggmr/Lab/Envs/asdf_virtual/build/django-parsley/setup.py", line 116, in <module>
long_description=read("README.md"),
File "/Users/prggmr/Lab/Envs/asdf_virtual/build/django-parsley/setup.py", line 11, in read
return open(os.path.join(os.path.dirname(__file__), fname)).read()
IOError: [Errno 2] No such file or directory: '/Users/prggmr/Lab/Envs/asdf_virtual/build/django-parsley/README.md'
I'm starting with django-parsley, it's a very nice app to develop django projects. It's very easy to configure and to use. But I have a problem using django-parsley to generate the client parsley validation in the django admin, I have this bug with django 1.6.1 and 1.6.7. The problem is related with select field parsley generation, all input fields are generated correctly, and the parsley.js validation works fine, but the data-parsley attribute of the select fields are missing.
I debugged for long time the django source and the html tags generated for the select fields don't contain the data-parsley attributes.
For now, I'm not using django-parsely for the django admin in my applications because not all fields are validated correctly.
I've searched online and I can't find any other developer comment regarding this problem. If anybody have this problem, or is able to find the solution, I'll be happy to use it.
Check and remove body of $(this).parsley() if proper
Having a basic issue after installing django-parsley - the following error is displaying when I try to run the python manage.py runserver
command:
from parsley.decorators import parsleyfy
ModuleNotFoundError: No module named 'parsley'
If parsley is a different dependency that must be installed in the project, could the docs be updated to reflect that? I can't figure out what to do to get this working.
Hi,
I noticed that you upgraded to parsley 2.x but haven't upgraded the regex parsley attribute https://github.com/agiliq/Django-parsley/blob/master/parsley/decorators.py#L38
Parsley 2.x uses a different attribute name for regex fields: 'data-parsley-pattern'
Thanks
Hi,
I appreciate the documentation however there is only example of using built-in validators on the Advanced Usage section. We will appreciate more if there are also an example of custom validators
Regards,
Dean
I created a form as below: http://pastebin.com/Tca78SQ5
but it doesn't call the clean_confirm_password.
data-parsley-required="true" should be sufficient. data-parsley-mincheck="1" doesn't work.
I have experimented with using django-parsley in the admin with Django 1.6.
I am seeing the error "You must bind Parsley on an existing element." in the Firefox console.
This appears to get triggered via the following code from parsley.js:
if (false !== ParsleyUtils.get(window, 'ParsleyConfig.autoBind'))
$(document).ready(function () {
// Works only on `data-parsley-validate`.
$('[data-parsley-validate]').parsley();
I have then tried setting ParsleyConfig.autoBind = false
, but there appears to be a problem with ParsleyUtils.get
, which returns undefined for false
.
This appears to be fixed in Parsley 2.0.2.
Also, parsley()
is only called in 2.0.2 automatically, if matching elements have been found:
if (false !== ParsleyUtils.get(window, 'ParsleyConfig.autoBind'))
$(document).ready(function () {
// Works only on `data-parsley-validate`.
if ($('[data-parsley-validate]').length)
$('[data-parsley-validate]').parsley();
});
Given this, and that there are probably more bug fixes in the latest parsley release, it should get updated with django-parsley.
I will provide a pull request for this.
I have noticed the change made in parsley 2.x in regard to type errors from data-parsley-'specific type'-message to the general type error message, data-parsley-type-message, but there is no adjustment in django-parsley. I wonder when this will be reflected.
Cheers.
The 0.1
release on PyPI doesn't include the static
folder inside the parsley
app, so everything throws a 404 on trying to load the JavaScript libraries.
> mkvirtualenv parsleytest
> workon parsleytest
> pip install django-parsley
[... install proceeds ...]
> cd lib/python2.7/site-packages/parsley
> tree
.
├── __init__.py
├── __init__.pyc
├── decorators.py
├── decorators.pyc
├── mixins.py
├── mixins.pyc
├── models.py
├── models.pyc
└── tests
├── __init__.py
├── __init__.pyc
├── admin.py
├── admin.pyc
├── forms.py
├── forms.pyc
├── models.py
├── models.pyc
├── tests.py
├── tests.pyc
├── views.py
└── views.pyc
Can you please put managed = False in Student model's Meta so it doesn't get created in db, or just remove the model. Thx
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.