-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(votepeloclima): Implemented widget and field to inline array fil…
…eds social media anda milestones
- Loading branch information
1 parent
6f8f561
commit d5c195d
Showing
6 changed files
with
124 additions
and
18 deletions.
There are no files selected for viewing
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
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
32 changes: 32 additions & 0 deletions
32
..._eleicoes/votepeloclima/candidature/migrations/0006_alter_candidature_options_and_more.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 4.2 on 2024-07-22 21:30 | ||
|
||
import django.contrib.postgres.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('candidature', '0005_alter_candidatureflow_candidature_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='candidature', | ||
options={'verbose_name': 'Candidatura'}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='candidatureflow', | ||
options={'verbose_name': 'Formulário'}, | ||
), | ||
migrations.AddField( | ||
model_name='candidature', | ||
name='milestones', | ||
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=140), blank=True, null=True, size=5), | ||
), | ||
migrations.AddField( | ||
model_name='candidature', | ||
name='social_media', | ||
field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(blank=True), blank=True, null=True, size=5), | ||
), | ||
] |
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
37 changes: 33 additions & 4 deletions
37
app/org_eleicoes/votepeloclima/candidature/static/js/inline-array-widget.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,45 @@ | ||
(function ($) { | ||
"use strict"; | ||
$(function () { | ||
const maxSize = $('#inline-array-add').data('size'); | ||
const name = $('#inline-array').data('name'); | ||
|
||
function updateInlineArray() { | ||
const totalInputs = $('#inline-array .d-flex').length; | ||
if (totalInputs === 1) { | ||
$('#inline-array .d-flex').find('button').hide(); | ||
} else { | ||
$('#inline-array .d-flex').find('button').show(); | ||
} | ||
|
||
if (totalInputs === maxSize) { | ||
$('#inline-array-add').attr('disabled', 'disabled'); | ||
} else { | ||
$('#inline-array-add').removeAttr('disabled'); | ||
} | ||
|
||
$('#inline-array .d-flex').each((i, item) => { | ||
$(item).find('input').attr('name', `${name}_${i}`) | ||
}) | ||
} | ||
|
||
$('#inline-array-add').click(() => { | ||
const $div = $('#inline-array .d-flex').first().clone(); | ||
$div.find('input').val(''); | ||
$('#inline-array').append($div); | ||
const totalInputs = $('#inline-array .d-flex').length; | ||
if (totalInputs < maxSize) { | ||
const $div = $('#inline-array .d-flex').first().clone(); | ||
$div.find('input').val(''); | ||
$div.find('button').show(); | ||
$('#inline-array').append($div); | ||
updateInlineArray(); | ||
} | ||
}); | ||
|
||
function inlineDelete(target) { | ||
$(target).parent().remove(); | ||
updateInlineArray(); | ||
}; | ||
|
||
window.inlineDelete=inlineDelete; | ||
updateInlineArray(); | ||
window.inlineDelete = inlineDelete; | ||
}); | ||
}(jQuery)); |
21 changes: 12 additions & 9 deletions
21
app/org_eleicoes/votepeloclima/candidature/templates/forms/widgets/inline_array.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
<div id="inline-array"> | ||
<div class="d-flex"> | ||
<input type="{{widget.type}}"{% include "django/forms/widgets/attrs.html" %}/> | ||
<button type="button" onclick="inlineDelete(this)"> | ||
Remover | ||
</button> | ||
</div> | ||
<div id="inline-array" data-name="{{ widget.name }}"> | ||
{% for widget in widget.subwidgets %} | ||
{% if widget.value or forloop.counter < 3 %} | ||
<div class="d-flex mb-2"> | ||
<input type="{{ widget.type }}" name="{{ widget.name }}" id="{{ widget.id }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}/> | ||
<button type="button" class="btn btn-danger ml-2" onclick="inlineDelete(this)"> | ||
Remover | ||
</button> | ||
</div> | ||
{% endif %} | ||
{% endfor %} | ||
</div> | ||
<button type="button" id="inline-array-add"> | ||
<button type="button" id="inline-array-add" class="btn btn-primary mt-2" data-size="{{ widget.size }}"> | ||
Adicionar | ||
</button> | ||
<input type="hidden" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}> |