Active/inactive client functionality added
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
from django import forms
|
||||
from .models import Clientes
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
class ClienteForm(forms.ModelForm):
|
||||
fecha_baja = forms.DateField(
|
||||
required=False,
|
||||
initial=datetime.now(),
|
||||
input_formats=["%Y-%m-%d"],
|
||||
widget=forms.DateInput(attrs={'type':'date'},format="%Y-%m-%d")
|
||||
)
|
||||
class Meta:
|
||||
model = Clientes
|
||||
fields = ('RFC','Nombre','Activo','fecha_baja')
|
||||
@@ -22,10 +22,9 @@
|
||||
{% render_field form.Activo class+="form-checkbox" type="checkbox" %}
|
||||
<label class="form-check-label" for="{{form.Activo.label}}">Activo</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group">
|
||||
{% render_field form.fecha_baja.label %}
|
||||
{% render_field form.fecha_baja placeholder=form.fecha_baja.label class+="form-control" type="date" %}
|
||||
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
@@ -33,6 +32,14 @@
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
window.addEventListener("load", (event)=>{
|
||||
if(!id_Activo.checked){
|
||||
id_fecha_baja.setAttribute('required','')
|
||||
}else{
|
||||
id_fecha_baja.removeAttribute('requied')
|
||||
}
|
||||
})
|
||||
|
||||
id_fecha_baja.addEventListener('click',(event)=>{
|
||||
|
||||
if(id_Activo.checked){
|
||||
@@ -41,6 +48,16 @@
|
||||
return
|
||||
}
|
||||
})
|
||||
id_Activo.addEventListener('click', (event)=>{
|
||||
|
||||
if(id_Activo.checked){
|
||||
id_fecha_baja.value=''
|
||||
id_fecha_baja.removeAttribute('required')
|
||||
|
||||
}else{
|
||||
id_fecha_baja.setAttribute('required','')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock scripts %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user