Comments (5)
From stan.madueke on June 29, 2010 13:17:34
You're quite right -- this should be handled by the plugin internally. I'd appreciate a patch, if you've got the time to code one. Otherwise, I'll get to it sometime this weekend.
Status: Accepted
Owner: stan.madueke
from django-dynamic-formset.
From [email protected] on June 29, 2010 13:52:00
The cheesy fix would look something like this:
@@ -145,6 +146,9 @@
updateElementIndex($(this), options.prefix, formCount);
});
$('#id_' + options.prefix + '-TOTAL_FORMS').val(formCount + 1);
-
if (formCount+1 >= $('#id_' + options.prefix + '-MAX_NUM_FORMS').val()) {
-
$(buttonRow).hide();
-
} // If a post-add callback was supplied, call it with the added form: if (options.added) options.added(row); return false;
Basically just hide the add another link if the form count is bigger than the max.
Making the link re-appear probably wouldn't be that hard. Just add the right code around line 64. The problem is knowing what the "bottomRow" is called since it seems to be either just an 'a' element or sometime inside of a tr. I wasn't confident enough to create a selector which would always work.
For my use-case I won't be letting user remove forms so this cheesy fix should work for me for now.
Let me know if there is anything wrong with my patch, but practically it seems to work.
Thanks for taking this key functionality and creating a jQuery plug in for it. It is really helpful. Hopefully it can continue to mature and become standard and robust.
from django-dynamic-formset.
From [email protected] on June 29, 2010 14:13:56
I posted a bit pre-emptively.
I have an expanded patch with addresses when the number of forms on the page is already the MAX_NUM_FORMS. It also handles MAX_NUM_FORMS not having a value (which is pretty common).
--- jquery.formset.js.orig.js 2010-04-13 02:40:18.000000000 -0400
+++ jquery.formset.js 2010-06-29 17:11:17.000000000 -0400
@@ -64,6 +64,7 @@
// Also update names and IDs for all remaining form controls so they remain in sequence:
var forms = $('.' + options.formCssClass).not('.formset-custom-template');
$('#id_' + options.prefix + '-TOTAL_FORMS').val(forms.length);
for (var i=0, formCount=forms.length; i<formCount; i++) {
applyExtraClasses(forms.eq(i), i);
forms.eq(i).find('input,select,textarea,label').each(function() {
@@ -135,6 +136,11 @@
$$.filter(':last').after('' + options.addText + '');
addButton = $$.filter(':last').next();
}
-
// Hide the addButton if we already have the max num of forms.
-
if ($('#id_' + options.prefix + '-MAX_NUM_FORMS').val() &&
-
$('#id_' + options.prefix + '-TOTAL_FORMS').val() >= $('#id_' + options.prefix + '-MAX_NUM_FORMS').val()) {
-
$(addButton).hide();
-
@@ -145,6 +151,10 @@
} addButton.click(function() { var formCount = parseInt($('#id_' + options.prefix + '-TOTAL_FORMS').val()), row = options.formTemplate.clone(true).removeClass('formset-custom-template'),
updateElementIndex($(this), options.prefix, formCount);
});
$('#id_' + options.prefix + '-TOTAL_FORMS').val(formCount + 1); -
if ($('#id_' + options.prefix + '-MAX_NUM_FORMS').val() &&
-
formCount+1 >= $('#id_' + options.prefix + '-MAX_NUM_FORMS').val()) {
-
$(buttonRow).hide();
-
} // If a post-add callback was supplied, call it with the added form: if (options.added) options.added(row); return false;
from django-dynamic-formset.
From stan.madueke on June 29, 2010 21:34:27
Thanks! I'll merge this in later today.
from django-dynamic-formset.
From stan.madueke on July 03, 2010 18:16:23
This has been fixed in trunk.
Status: Fixed
from django-dynamic-formset.
Related Issues (20)
- No remove button and add won't add form HOT 3
- Simlutaneous deletion and creation not working HOT 8
- I have installed django_dynamic_formsets but it says the module not installed dynamic_formsets. I'm using windows 10 with python version 3.8.5.
- Limit minimum and maximum of formsets
- Nested formsets HOT 1
- Demo package download link is down
- Is it possible to include html inside addText or deleteText? HOT 4
- nothing
- deleteContainerClass does not seem to be working
- Only rows specified in 'extra' are saved and rows above 'extra' do not have default values
- deleteContainerClass not working properly HOT 1
- how to use onKeyup for django formset input fields
- delete button shows up only once in django formset that is created with queryset to edit
- Clicking on add row in update mode displays foreign keys even if label is none. HOT 1
- Input field id show NaN instead of increased number even with prefix set HOT 6
- does not seem to work with file fields HOT 1
- Deleting instance not working when hideLastAddForm is true HOT 1
- Unsetting and resetting the current formset
- Add option to either append or prepend delete button HOT 1
- Render add button even when formset is empty
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-dynamic-formset.