Created
November 16, 2020 22:17
-
-
Save pedrohsbarbosa99/f6c93ec761c034304367ef5c1c5e7db7 to your computer and use it in GitHub Desktop.
Mask input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load static %} | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<meta name="description" content=""> | |
<meta name="author" content=""> | |
<!-- Bootstrap core CSS --> | |
<link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet"> | |
<link href="{% static 'vendor/js/scripts.js' %}"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% block title %}Cadastrar contato | {% endblock %} | |
{% block content %} | |
{% include 'parciais/_messages.html' %} | |
<div class="container"> | |
<h2 class="mt-3 mb-3">Cadastre seus contatos aqui.</h2> | |
<form action="{% url 'dashboard' %}" method="POST" enctype="multipart/form-data"> | |
{% csrf_token %} | |
<table class="table"> | |
{{ form }} | |
<tr> | |
<td> | |
<button type="submit" class="btn btn-primary">Enviar</button> | |
</td> | |
</tr> | |
</table> | |
</form> | |
</div> | |
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.forms import widgets | |
from django.forms.widgets import TextInput | |
from contatos.models import Contato | |
from django import forms | |
class FormContato(forms.ModelForm): | |
class Meta: | |
model = Contato | |
exclude = () | |
widgets = { | |
'telefone': TextInput(attrs={ | |
'id':'telefone-mask' | |
}), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById('telefone-mask').addEventListener('blur', function (e) { | |
var x = e.target.value.replace(/\D/g, '').match(/(\d{3})(\d{3})(\d{4})/); | |
e.target.value = '(' + x[1] + ') ' + x[2] + '-' + x[3]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment