Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/python273/dogeforms
jQuery plugin that helps create AJAX forms with Django
https://github.com/python273/dogeforms
ajax-form django jquery jquery-plugin
Last synced: 12 days ago
JSON representation
jQuery plugin that helps create AJAX forms with Django
- Host: GitHub
- URL: https://github.com/python273/dogeforms
- Owner: python273
- License: mit
- Created: 2016-09-15T04:16:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-15T04:35:01.000Z (over 8 years ago)
- Last Synced: 2024-12-17T15:44:09.906Z (2 months ago)
- Topics: ajax-form, django, jquery, jquery-plugin
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme-ru.md
- License: LICENSE
Awesome Lists containing this project
README
Dogeforms - Simple Django AJAX forms
================================
Этот jQuery плагин помогает вам создавать AJAX формы с Django.Функции:
* AJAX
* Отображение ошибок
* Поддержка Formset## Использование
Добавьте jQuery и плагин на страницу```html
```
Создайте форму
```html{% csrf_token %}
Message
{{ form.message }}
Send
```
Задогеформите это
```html$.dogeform({
formId: 'contact-form',
submitBtnId: 'contact-form-submit'
});```
Создайте view
```python
class ContactFormView(View):
def get(self, request):
return render(request, 'contact_form.html', {
'form': ContactForm()
})def post(self, request):
form = ContactForm(request.POST)if form.is_valid():
send_message(form.cleaned_data['message'])
return JsonResponse({'ok': True, 'redirect': reverse('success')})return JsonResponse({'errors': form.errors})
```## API
### Dogeform параметры
* formId - ID формы
* submitBtnId - ID кнопки отправки формы
* success (function) - эта функция вызывается, если ответ содержит `ok` с значением `true`
* loadingText (html) - этот текст показывается, пока не придет ответ. Например можно показывать символ загрузки.
* successTooltipText (text) - этот текст показывается в тултипе, если ответ содержит `ok` с значением `true` (требуется bootstrap)### Redirect
Если ответ содержит `redirect`, то пользователь будет перенаправлен по этой ссылке. Пример:
```json
{"ok": true, "redirect": "/success/"}
```