conditional fields
This commit is contained in:
2
VERSION
2
VERSION
@@ -1 +1 @@
|
||||
Version 2.4.7-stable+timestamp.2013.06.01.18.23.56
|
||||
Version 2.4.7-stable+timestamp.2013.06.03.17.47.22
|
||||
|
||||
@@ -78,6 +78,7 @@ jQuery(function() {
|
||||
if(flash.html()) flash.append('<span id="closeflash">×</span>').slideDown();
|
||||
web2py_ajax_init(document);
|
||||
web2py_event_handlers();
|
||||
web2py_show_if();
|
||||
});
|
||||
|
||||
function web2py_trap_form(action,target) {
|
||||
@@ -216,3 +217,26 @@ function web2py_validate_entropy(myfield, req_entropy) {
|
||||
if(!myfield.hasClass('entropy_check')) myfield.on('keyup', validator).on('keydown', validator).addClass('entropy_check');
|
||||
}
|
||||
|
||||
function web2py_show_if() {
|
||||
var triggers = {};
|
||||
var show_if = function() {
|
||||
var t = jQuery(this);
|
||||
var id = t.attr('id');
|
||||
t.attr('value',t.val());
|
||||
for(var k=0; k<triggers[id].length; k++) {
|
||||
var dep = jQuery('#'+triggers[id][k]);
|
||||
var tr = jQuery('#'+triggers[id][k]+'__row');
|
||||
if(t.is(dep.attr('data-show-if'))) tr.slideDown();
|
||||
else tr.hide();
|
||||
}
|
||||
};
|
||||
jQuery('[data-show-trigger]').each(function(){
|
||||
var name = jQuery(this).attr('data-show-trigger');
|
||||
if(!triggers[name]) triggers[name] = [];
|
||||
triggers[name].push(jQuery(this).attr('id'));
|
||||
});
|
||||
for(var name in triggers) {
|
||||
jQuery('#'+name).change(show_if).keyup(show_if);
|
||||
show_if.call(jQuery('#'+name));
|
||||
};
|
||||
}
|
||||
@@ -78,6 +78,7 @@ jQuery(function() {
|
||||
if(flash.html()) flash.append('<span id="closeflash">×</span>').slideDown();
|
||||
web2py_ajax_init(document);
|
||||
web2py_event_handlers();
|
||||
web2py_show_if();
|
||||
});
|
||||
|
||||
function web2py_trap_form(action,target) {
|
||||
@@ -216,3 +217,26 @@ function web2py_validate_entropy(myfield, req_entropy) {
|
||||
if(!myfield.hasClass('entropy_check')) myfield.on('keyup', validator).on('keydown', validator).addClass('entropy_check');
|
||||
}
|
||||
|
||||
function web2py_show_if() {
|
||||
var triggers = {};
|
||||
var show_if = function() {
|
||||
var t = jQuery(this);
|
||||
var id = t.attr('id');
|
||||
t.attr('value',t.val());
|
||||
for(var k=0; k<triggers[id].length; k++) {
|
||||
var dep = jQuery('#'+triggers[id][k]);
|
||||
var tr = jQuery('#'+triggers[id][k]+'__row');
|
||||
if(t.is(dep.attr('data-show-if'))) tr.slideDown();
|
||||
else tr.hide();
|
||||
}
|
||||
};
|
||||
jQuery('[data-show-trigger]').each(function(){
|
||||
var name = jQuery(this).attr('data-show-trigger');
|
||||
if(!triggers[name]) triggers[name] = [];
|
||||
triggers[name].push(jQuery(this).attr('id'));
|
||||
});
|
||||
for(var name in triggers) {
|
||||
jQuery('#'+name).change(show_if).keyup(show_if);
|
||||
show_if.call(jQuery('#'+name));
|
||||
};
|
||||
}
|
||||
@@ -78,6 +78,7 @@ jQuery(function() {
|
||||
if(flash.html()) flash.append('<span id="closeflash">×</span>').slideDown();
|
||||
web2py_ajax_init(document);
|
||||
web2py_event_handlers();
|
||||
web2py_show_if();
|
||||
});
|
||||
|
||||
function web2py_trap_form(action,target) {
|
||||
@@ -216,3 +217,26 @@ function web2py_validate_entropy(myfield, req_entropy) {
|
||||
if(!myfield.hasClass('entropy_check')) myfield.on('keyup', validator).on('keydown', validator).addClass('entropy_check');
|
||||
}
|
||||
|
||||
function web2py_show_if() {
|
||||
var triggers = {};
|
||||
var show_if = function() {
|
||||
var t = jQuery(this);
|
||||
var id = t.attr('id');
|
||||
t.attr('value',t.val());
|
||||
for(var k=0; k<triggers[id].length; k++) {
|
||||
var dep = jQuery('#'+triggers[id][k]);
|
||||
var tr = jQuery('#'+triggers[id][k]+'__row');
|
||||
if(t.is(dep.attr('data-show-if'))) tr.slideDown();
|
||||
else tr.hide();
|
||||
}
|
||||
};
|
||||
jQuery('[data-show-trigger]').each(function(){
|
||||
var name = jQuery(this).attr('data-show-trigger');
|
||||
if(!triggers[name]) triggers[name] = [];
|
||||
triggers[name].push(jQuery(this).attr('id'));
|
||||
});
|
||||
for(var name in triggers) {
|
||||
jQuery('#'+name).change(show_if).keyup(show_if);
|
||||
show_if.call(jQuery('#'+name));
|
||||
};
|
||||
}
|
||||
@@ -81,6 +81,27 @@ def safe_float(x):
|
||||
return 0
|
||||
|
||||
|
||||
def show_if(cond):
|
||||
if not cond:
|
||||
return None
|
||||
base = "%s_%s" % (cond.first.tablename, cond.first.name)
|
||||
if ((cond.op.__name__ == 'EQ' and cond.second == True) or
|
||||
(cond.op.__name__ == 'NE' and cond.second == False)):
|
||||
return base,":checked"
|
||||
if ((cond.op.__name__ == 'EQ' and cond.second == False) or
|
||||
(cond.op.__name__ == 'NE' and cond.second == True)):
|
||||
return base,":not(:checked)"
|
||||
if cond.op.__name__ == 'EQ':
|
||||
return base,"[value='%s']" % cond.second
|
||||
if cond.op.__name__ == 'NE':
|
||||
return base,"[value!='%s']" % cond.second
|
||||
if cond.op.__name__ == 'CONTAINS':
|
||||
return base,"[value~='%s']" % cond.second
|
||||
if cond.op.__name__ == 'BELONGS' and isinstance(cond.second,(list,tuple)):
|
||||
return base,','.join("[value='%s']" % (v) for v in cond.second)
|
||||
raise RuntimeError("Not Implemented Error")
|
||||
|
||||
|
||||
class FormWidget(object):
|
||||
"""
|
||||
helper for SQLFORM to generate form input fields
|
||||
@@ -104,9 +125,13 @@ class FormWidget(object):
|
||||
_id='%s_%s' % (field._tablename, field.name),
|
||||
_class=cls._class or
|
||||
widget_class.match(str(field.type)).group(),
|
||||
_name=field.name,
|
||||
_name=field.name,
|
||||
requires=field.requires,
|
||||
)
|
||||
if getattr(field,'show_if',None):
|
||||
trigger, cond = show_if(field.show_if)
|
||||
attr['_data-show-trigger'] = trigger
|
||||
attr['_data-show-if'] = cond
|
||||
attr.update(widget_attributes)
|
||||
attr.update(attributes)
|
||||
return attr
|
||||
@@ -1740,6 +1765,7 @@ class SQLFORM(FORM):
|
||||
return CAT(
|
||||
DIV(_id=panel_id, _style="display:none;", *criteria), fadd)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def grid(query,
|
||||
fields=None,
|
||||
|
||||
Reference in New Issue
Block a user