The subject line pretty much says it all, the list:integer and list:string
data types don't appear to respect the show_if parameter (from this
<http://web2py.com/books/default/chapter/29/07/forms-and-validators#Conditional-fields>
section
in the book). I needed them to, and had a workaround in js for a while, but
wanted to use all of the built-in web2py goodness for everything,
regardless of list data types (I'm using the list types in
sqlform.smartgrid already)

In brief, it comes down to the fact that the ID is different for list types
on the ul element containing each of the list items. Given a major priority
of web2py is backwards compatibility (one I highly appreciate),I wrote it
in a way that won't break existing CSS/JS/etc. for things referencing that
UL containing the list items. This is not exactly "clean" in my opinion,
but it's been running in my test environment for a few months with no
issues.

Even though though it takes 2 additional CSS selector lookups from jquery
to perform on each change of the monitored element, this handling should be
able to be reused for any additional data types that don't properly handle
the show_if situation, and the parent_tr reference can be used as a backup
for any future functionality that also has issues with cross-referencing
from the UL element to it's parent TR element. Note, I'm quite abysmal at
JS IMHO, though I can hack my way through it enough to be dangerous. So
there may be a better way to do this work than storing the parent element
name on the child as an attribute, then adding a fallthrough handler to
examine and select based upon said attribute. Given there doesn't exist a
parent reference in CSS (for good reason, performance wise), this is the
most efficient method I came up with in the 30 seconds I spent considering
before I wrote it.

I can work on forking and throwing a pull request up on github
<https://github.com/web2py/web2py>if you prefer, and if someone can confirm
it's the "official home" of web2py code now. Might take me a short bit to
find the time to spin up a dev environment that's "clean" enough to do so,
but that's been on my todo list for a while. Otherwise the patch is
attached here for review.

You may also consider this my agreement to the Web2py Contributor Agreement
<http://www.web2py.com/init/static/web2py_contributor_agreement.pdf> (again
I think, though I don't entirely remember if the changes I made were to
web2py or some of the contrib libraries), unless you'd rather require I
upload a signed copy somewhere.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff -ur web2py_orig/applications/admin/static/js/web2py.js web2py/applications/admin/static/js/web2py.js
--- web2py_orig/applications/admin/static/js/web2py.js  2016-08-02 18:48:50.000000000 -0500
+++ web2py/applications/admin/static/js/web2py.js       2016-08-02 18:49:13.000000000 -0500
@@ -539,6 +539,7 @@
         for(var k = 0; k < triggers[id].length; k++) {
           var dep = $('#' + triggers[id][k], target);
           var tr = $('#' + triggers[id][k] + '__row', target);
+          if(!tr.length) tr = $('#' + $('#' + triggers[id][k], target).attr('parent_tr'), target);
           if(t.is(dep.attr('data-show-if'))) tr.slideDown();
           else tr.hide();
         }
diff -ur web2py_orig/gluon/sqlhtml.py web2py/gluon/sqlhtml.py
--- web2py_orig/gluon/sqlhtml.py        2016-08-02 18:53:11.000000000 -0500
+++ web2py/gluon/sqlhtml.py     2016-08-02 18:33:04.000000000 -0500
@@ -296,6 +296,9 @@
                           value=v, hideerror=k < len(nvalue) - 1,
                           requires=requires),
                     **attributes) for (k, v) in enumerate(nvalue)]
+        default = dict(value=value)
+        attributes = cls._attributes(field, default, **attributes)
+        attributes['_parent_tr'] = attributes['_id'] + '__row'
         attributes['_id'] = _id + '_grow_input'
         attributes['_style'] = 'list-style:none'
         attributes['_class'] = 'w2p_list'

Reply via email to