Skip to content

Instantly share code, notes, and snippets.

@taizarm
Created Jul 21, 2014
Embed
What would you like to do?
class CadastroUsuarioForm(forms.Form):
cep = forms.IntegerField(widget=CEPInput(address={
'street': 'id_endereco',
'district': 'id_bairro',
'city': 'id_cidade',
'state': 'id_estado'
},
attrs={'class': 'cepMask', 'placeholder': 'CEP'}),
help_text='Ao inserir o CEP, os dados de endereço serão preenchidos automaticamente.')
endereco = forms.CharField(max_length=255, label='Endereço',
widget=forms.TextInput(attrs={'placeholder': 'Endereço'}))
numero = forms.IntegerField(label='Número',
widget=forms.TextInput(attrs={'class': 'numeroEnderecoMask', 'placeholder': 'Número'}))
complemento = forms.CharField(max_length=255, required=False,
widget=forms.TextInput(attrs={'placeholder': 'Complemento'}))
bairro = forms.CharField(max_length=255, widget=forms.TextInput(attrs={'placeholder': 'Bairro'}))
cidade = forms.CharField(max_length=255, widget=forms.TextInput(attrs={'placeholder': 'Cidade'}))
estado = BRStateChoiceField(widget=forms.TextInput(attrs={'placeholder': 'Estado'}))
{% extends "base_site_simples.html" %}
{% block head %}
{% load staticfiles %}
<script type="text/javascript" src="{% static 'tesportessite/jquery-1.8.2.min.js' %}"></script>
<script type="text/javascript" src="{% static 'tesportessite/jquery-ui-1.10.4.min.js' %}"></script>
<script type="text/javascript" src="{% static 'tesportessite/jquery.mask.min.js' %}"></script>
<link rel="stylesheet" href="{% static 'tesportessite/jquery-ui-1.10.4.custom.css' %}"></link>
<script type="text/javascript">
function unmask(){
$('.cepMask').unmask();
};
$(function() {
$('.cepMask').mask('00000-000');
});
$(document).ready(function(){
$(".zip-field").blur(function(){
var arr;
// validates CEP
var regex = /^([0-9]{5})[-. ]?([0-9]{3})$/;
if (regex.test($(".zip-field").val()))
{
$.get('/cep/'+$(".zip-field").val()+'/', function(data,status)
{
eval("var arr = "+data);
$("#"+address.street).val(arr.street);
$("#"+address.district).val(arr.district);
$("#"+address.city).val(arr.city);
$("#"+address.state).val(arr.state);
});
}
});
});
</script>
{% endblock head %}
{% block content %}
<form class="signup cadastro_usuario" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{% for field in form %}
<div id="p_{{ field.id_for_label }}" class="field_wrapper">
<p>
<span>{{ field }}</span>
</p>
<p class="help-text">
{{ field.help_text }}
</p>
<p class="help-text">
<span class="field_error_message">{{ field.errors|striptags }}</span>
</p>
</div>
{% endfor %}
<button type="submit" value="Cadastrar" onclick="unmask();" >Cadastrar</button>
</form>
{% endblock %}
# coding=utf-8
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
#Site e Admin
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('site.urls')),
#django-cep
url(r'^cep/', include('cep.urls')),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment