ok, here is a patch against current *trunk*. this should never allow
you to remove the last item from the list. note that when the list is
empty (showing one field with no data) the + and - buttons appear to be
no-op.
On 12/20/12 7:06 , Massimo Di Pierro wrote:
For now I have remove the "-" button.
On Wednesday, 19 December 2012 23:48:37 UTC-6, howesc wrote:
ooops. i added the - and didn't test the "only 1 row case". i'll try and
create a patch tomorrow for it.
mind opening a ticket in google code?
thanks,
christian
On Tuesday, December 18, 2012 8:17:11 AM UTC-8, Daniele wrote:
The newest version of web2py has added some + and - clickable links to
form elements so that it is possible to remove the element. However, if
there is only one element and one clicks the "-", the form disappears and
there's no way to get the form element back without refreshing the page.
I'll post an image so that you can see what it looks like.
I think this is a bug with the newest version because my code hasn't
changed at all. There was only a "+" before...
--
diff -r 4c55a243c4c2 gluon/sqlhtml.py
--- a/gluon/sqlhtml.py Thu Dec 20 09:22:24 2012 -0600
+++ b/gluon/sqlhtml.py Thu Dec 20 10:45:52 2012 -0800
@@ -263,18 +263,27 @@
jQuery.fn.grow_input = function() {
return this.each(function() {
var ul = this;
- jQuery(ul).find(":text").after('<a
href="javascript:void(0)">+</a>').keypress(function (e) { return (e.which ==
13) ? pe(ul) : true; }).next().click(function(){ pe(ul) });
+ jQuery(ul).find(":text").after('<a href="javascript:void(0)">+</a> <a
href="javascript:void(0)">-</a>').keypress(function (e) { return (e.which ==
13) ? pe(ul, e) : true; }).next().click(function(e){ pe(ul, e)
}).next().click(function(e){ rl(ul, e)});
});
};
function pe(ul, e) {
var new_line = ml(ul);
rel(ul);
- new_line.appendTo(ul);
+ if ($(e.target).parent().is(':visible')) {
+ //make sure we didn't delete the element before we insert after
+ new_line.insertAfter($(e.target).parent());
+ } else {
+ //the line we clicked on was deleted, just add to end of list
+ new_line.appendTo(ul);
+ }
new_line.find(":text").focus();
return false;
}
function rl(ul, e) {
- jQuery(e.target).parent().remove();
+ if (jQuery(ul).children().length > 1) {
+ //only remove if we have more than 1 item so the list is never empty
+ $(e.target).parent().remove();
+ }
}
function ml(ul) {
var line = jQuery(ul).find("li:first").clone(true);