I'd many boolean field in my forms and subforms and then the True/false (Yes/No) dropdown method ( as here: http://forums.nubuilder.cloud/viewtopic.php?f=6&t=7889 ) wasn't very clear. And I'm lazy so why using two clicks if I can use one ?
So I tried to add a new object type called checkbox to nuBuilderPro. I'm not a developer : use the following at your own risk !
Here are the modifications I've made to different files and it seems to work as I want.
The zip archive attached contains all the patches and other files needed.
First, I added a nuGetObjectCheckbox function in nuapi.php based on other nuGetObject functions :
Code: Select all
function nuGetObjectCheckbox($recordArray, $o, $recordID, $hashData) {
$nuObject = nuBaseObject($o, $recordID, $hashData);
if ($recordID == '-1' or nuUseDefault($o)) {
$nuObject->value = nuGetDefaultValue($o->sob_all_default_value_sql, $hashData);
} else {
if($recordArray != "" and array_key_exists($o->sob_all_name, $recordArray)) {
$nuObject->value = $recordArray[$o->sob_all_name];
}
}
Code: Select all
if ($o->sob_all_type == 'checkbox') {
$OBJ[] = nuGetObjectCheckbox($recordArray, $o, $recordID, $hashData);
}
In nucommon.js, add a push for the new type (function nuSetObjectTypeProperties) :
Code: Select all
a.push('dropdown');
a.push('checkbox');
a.push('html');
In nueditform.js, add a nuBuildCheckBox function in nuRecordObjects :
Code: Select all
this.nuBuildCheckBox = function(o,i,p){
var e = document.createElement('input'); //-- create a new checkbox object
e.setAttribute('type', 'checkbox');
this.nuObjectWrapper(o,i,p);
this.nuSetAttributes(e,o,i);
$('#'+'td_right_'+e.id).append(e);
nuObjectSize(o,e,i,false);
$('#' + e.id).css( 'text-align', nuFormatAlign(o[i].align));
if ( o[i].read_only == '1' ) {
$('#' + e.id).prop("disabled", true);
}
}
checkbox need a value, so we add the new type.
Code: Select all
if($.inArray(o[i].type , ['text','display','button','checkbox']) != -1){
if(o[i].value==null){
o[i].value = '';
}
e.setAttribute('value', o[i].value);
}
Code: Select all
if(o[i].type == 'checkbox'){
var currentOnClick = e.getAttribute('onclick');
e.setAttribute('onclick', currentOnClick+';nuToggleCB(this)');
switch (o[i].value){
case "0":
e.checked = false;
break;
case "1":
e.checked = true;
break;
default:
e.indeterminate = true;
}
}
Code: Select all
if($.inArray(o[i].type , ['text','textarea','dropdown','checkbox','listbox','lookup']) != -1)
Code: Select all
function nuToggleCB(t){
if($('#'+t.id).prop('checked')==true){
$('#'+t.id).attr('value', "1");
}else{
$('#'+t.id).attr('value', "0");
}
}
Code: Select all
if(formObjects[i].type == 'dropdown'){ form.nuBuildDropdown (formObjects,i,parent);}
if(formObjects[i].type == 'checkbox'){ form.nuBuildCheckBox (formObjects,i,parent);}
if(formObjects[i].type == 'display'){ form.nuBuildDisplay (formObjects,i,parent);}
Code: Select all
$('#' + e.id).css({
'top' : form.top+'px',
'width' : (formWidth-40)+'px',
'left' : '0px',
'height' : formHeight+'px',
'position' : 'absolute',
'border-style' : 'none',
'text-align' : 'center'
Code: Select all
if(o[i].type != 'checkbox'){
$('#' + e.id).css( 'width', o[i].width+'px')
}
if(!xAndY){return;}
$('#' + e.id).css( 'height', o[i].height+'px')
To display 0 and 1 values as checkboxes in the Browse Form, we add a checkbox format in function nuTextFormats in nucommon.php :
Code: Select all
//-----checkbox format
$format[32]->type = 'checkbox';
$format[32]->format = 'cb';
$format[32]->decimal = '';
$format[32]->separator = '';
$format[32]->sample = 'checkbox';
$format[32]->phpdate = '';
$format[32]->sql = 'CONCAT(\'<input type="checkbox" \',IF(??,\'checked \',\'\'),\'disabled>\')';
Finally, there are 3 changes to make in the SQL base :
- add new checkbox type in the nuBuilder Objects dropdown type
add new format in the nuBuilder Form Browse tab
add a css color for .nu_checkbox in System Setup > Header
Code: Select all
.nu_dropdown {background-color : #7bce98}
.nu_checkbox {background-color : #FF6633}
.nu_html {background-color : #c497a6}
Result :
Browse Form before Browse Form with Checkboxes Subform before Subform with Checkboxes Edit Fom with Checkboxes Choose checkbox type and format :
It may be improved (style for disabled checkboxes for example) and I don't know if it's interesting for others than me
Once again, use with caution. not sure it doesn't break something in nuBuilder !!!