PDA

View Full Version : group repeat function is not working


ausceltus
01-23-2007, 01:43 PM
When selecting group repeat in a form it appears like it works the first time you save the group then fails after the group is edited the first time...

echologic
01-24-2007, 01:27 PM
Hi Ross,

What version of Fabrik are you using?

-Graylan King

rob
01-24-2007, 06:32 PM
hi

Do you mean that you have a form with a group with the "repeat group " option turned on.
You create 2 copies of the group, enter data and save the form.
Then when you come to edit the record created the two groups don't show?

If so then this is a bug, and I will add it to the list of things to do

Cheers
Rob

ausceltus
01-24-2007, 08:03 PM
I have upgraded from version1.0 to 1.01 today.. same problem

What I am saying is that on the front end the option is there to add another group section however it does not work...

I was indicating that when the group is first saved on the backend it works however once the group is edited on the backend and saved it will no longer work on the frontend

http://www.rabway.com/index.php?option=com_fabrik&Itemid=88888973
example above

rob
01-26-2007, 05:09 PM
Hi Ross

I've added this to "the list of things to do". Many thanks for reporting it

Cheers
Rob

ausceltus
01-31-2007, 11:24 AM
Is there any news on a fix for this problem?

rob
01-31-2007, 12:15 PM
no sorry

barnett
02-08-2007, 10:15 PM
I need this Group Repeat ability to work, b/c it currently doesn't work in the frontend or the backend with Fabrik 1.0.2. So I've done some preliminary investigation work.

My repeating group consists of a database join drop-down field and a text field. The HTML output to the Fabrik form for the group is as follows:

<div class="fabrikgrouptitle" id="title8">Checklist Location</div>
<a href="javascript:duplicateGroup( 8, '')"> + Add</a><a href="javascript:deleteLastClone( 8, '')"> | Delete</a>

<div class="fabrikLabel" id="mf_el_mf_el_checklist_var_text"><label for="mf_el_checklist_var">Check List Var</label></div>
<select onsubmit="javascript:submit_form();" id="mf_el_checklist_var" name="jos_users___checklist_var[]" class="inputbox" size="1" >
<option value="" selected="selected">Please Select</option>
<option value="1">CANADA</option>
<option value="2">UK</option>
<option value="3">USA</option>
</select>

<div class="fabrikLabel" id="mf_el_mf_el_test_field_text"><label for="mf_el_test_field">TESTING DATA<br /></label></div>
<input class="inputbox text" onsubmit="javascript:submit_form();" type="text" name="jos_users___test_field[]" size="50" maxlength="255" id="mf_el_test_field" value="" />


When I click the ADD a group button I get the following Javascript message: "group has no properties"
This error refers to the duplicateGroup() Javascript function:

function duplicateGroup(i, addJs){
var group = document.getElementById('group'+i);
var subgroups = group.getElementsByTagName('div');
var c = 0;
for (j = 0; j < subgroups.length; j++) {
if(subgroups[j].className == 'fabrikubGroup'){
c = c+1;
}
}
if(group.style.display == 'none'){
group.style.display = 'block';
var subgroup = $('subgroup'+i+'_0');
subgroup.style.display = 'block';
}else{
var subgroup = $('subgroup'+i+'_0');
subgroup.style.display = 'block';
var clone = subgroup.cloneNode(true);
clone.id = 'subgroup'+i+'_' + c;
c = c + 1;
group.appendChild(clone);
}
eval(addJs);
}


This Code seems to be looking for tags which don't exist around the group.
In my case it would be this:

<div id="group8">
<div class="fabrikubGroup">
<!-- 1st Instance of Group CODE HERE -->
</div>
</div>


And if I were to hit the ADD button it would be this:

<div id="group8">
<div class="fabrikubGroup">
<!-- 1st Instance of Group CODE HERE -->
</div>
<div class="fabrikubGroup">
<!-- 2nd Instance of Group CODE HERE -->
</div>
<div class="fabrikubGroup">
<!-- 3rd Instance of Group CODE HERE -->
</div>
</div>


So that is what I've found so far.
The correct containing tags for the groups aren't output.
What file produces this code?

-barnett

barnett
02-09-2007, 03:48 AM
Upon further testing the repeat group functionality works in the frontend, just not the backend.... don't know why but it has something to do with the code above not being output. I guess the form in the backend doesn't use the patTemplate file.

any help would be great.
-barnett

rob
02-19-2007, 11:04 AM
hi Thanks for the clarification on what was going wrong.
To get the repeat group working in the admin replace the entire function displayAdminForm() in components/com_fabrik/fabrik.html.php with


function displayAdminForm( $oForm, $arErrors, $data, $enctype, $tableId, $rowId, $lists, $jsActions ) {
global $mosConfig_live_site, $Itemid, $mainframe, $my, $_VERSION, $mosConfig_absolute_path;
if ( !$oForm->_admin ) {
require_once ( $mosConfig_absolute_path . "/includes/HTML_toolbar.php" );
}
$calenderCSSFile = "<link rel=\"stylesheet\" media=\"all\" type=\"text/css\" href=\"$mosConfig_live_site/includes/js/calendar/calendar-mos.css\" title=\"green\" />";
if ( method_exists( $mainframe, 'addCustomHeadTag' ) ) {
$mainframe->addCustomHeadTag($calenderCSSFile);
} else {
echo $calenderCSSFile;
}
$aIgnoreOnUpdate = array();
require_once( $mosConfig_absolute_path . "/components/com_fabrik/fabrik_params.xml.php" );

if( ($_VERSION->PRODUCT == 'Joomla!' && $_VERSION->RELEASE >= 1.5) == false){?>

<?php }?>
<!-- import the language module -->
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/includes/js/calendar/lang/calendar-en.js"></script>
<script type="text/javascript" language="Javascript" src="<?php echo $mosConfig_live_site; ?>/includes/js/overlib_mini.js"></script>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:10000;"></div>
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/includes/js/mambojavascript.js"></script>
<script type="text/javascript">
function submit_form(){
<?php
foreach( $oForm->_groups as $oGroup ){
foreach( $oGroup->_aElements as $oElement ){
if ( $oElement->elementtype_id == '5' and $oElement->use_wysiwyg == '1' ) {
$parsedName = preg_replace("/[^A-Za-z0-9]/", "_", $oElement->element_name);
getEditorContents("$parsedName", "$parsedName");
}
}
}
?>
return false;
}

function submitbutton(button){
$('task').value = button;
document.adminForm.submit();
}
/* duplicates the groups sub group and places it at the end of the group */

function duplicateGroup(i, addJs){
var group = document.getElementById('group'+i);
var subgroups = document.getElementsByClassName('fb_sub_group', group);
var c = subgroups.length;
if(subgroups[0].style.display == 'none'){
subgroups[0].style.display = 'block';
var subgroup = $('subgroup'+i+'_0');
subgroup.style.display = 'block';
}else{
var subgroup = $('subgroup'+i+'_0');
subgroup.style.display = 'block';
var clone = subgroup.cloneNode(true);
clone.id = 'subgroup'+i+'_' + c;
c = c + 1;
group.appendChild(clone);
}
eval(addJs);
}

/* removes the last duplicated subgroup */

function deleteLastClone(i, delJs){
var element = $('group'+i);
var subgroups = document.getElementsByClassName('fb_sub_group', element);
var c = subgroups.length;
var lastSubGroup = subgroups[c-1];
console.log(c);
if(c > 1){ // make sure we dont remove the origional sub group
c = c -1;
if(lastSubGroup != ''){
element.removeChild(lastSubGroup);
}
eval(delJs);
}else{
if( c == 1){
c = c -1;
lastSubGroup.style.display = 'none';
eval(delJs);
}
}
}
</script>
<?php
$oForm->getFormManagementJS();
$formwidth = $oForm->width;
$formalign = $oForm->align;
//TODO : fabrik : 0.5 : these should be defined in the admin section
$default_group_css = "left:10px;right:10px;background-color:#DCDCDC;padding:10px;border:0px solid black;";
echo "<div style=\"text-align:$formalign;\">\n";
if ( $oForm->_admin ) {
$formName = "adminForm";
$rootPath = $mosConfig_live_site."/administrator/index2.php";
$js = "onsubmit=\"javascript:submit_form();\"";
} else {
$formName = "fabrik".$oForm->id;
$rootPath = $mosConfig_live_site."/index.php";
$js = "";
}
echo ("<div class=\"componentheading\">".$oForm->form_title."</div>\n");
if ( (count( $arErrors ) > 0) and is_array( $arErrors ) ) {
echo "<p class=\"fabrikerror\">".$oForm->form_errmessage."</p>";
}
if ( $oForm->form_introtext != "" ) {
echo "<p>".$oForm->form_introtext."</p>\n" ;
}
?>
<form action="<?php echo $rootPath; ?>?option=com_fabrik" <?php echo $js;?> method="post" name="<?php echo $formName; ?>" id="<?php echo $formName; ?>" enctype="<?php echo $enctype; ?>" >
<?php
echo "<div style=\"width:" . $oForm->width .";border:0px solid black;\">\n";
$curGroupID = "";
$action_id = "";
$counter = 0;
$uploadCounter = 1;

$groupCounter = 0;
foreach( $oForm->_groups as $oGroup ){

if( $groupCounter != 0 ) {
}
$aHtmlGroupElements = array();
$oHtmlGroup = new stdClass;
$groupCounter ++;

$groupParams = new fabrikParams( $oGroup->attribs );
$canRepeatGroup = $groupParams->get( 'repeat_group_button', '0' );
$addJs = $groupParams->get( 'repeat_group_js_add' );
$addJs = str_replace('"', "'", $addJs);
$addJs = str_replace("\n", "", $addJs);
$addJs = str_replace("\r", "", $addJs);
$delJs = $groupParams->get( 'repeat_group_js_delete' );
$delJs = str_replace('"', "'", $delJs);
$showGroup = $groupParams->def( 'repeat_group_show_first', '1' );

if($showGroup == 0){
$oGroup->group_css .= ";display:none;";
}
$rubbish = array ("<br />", "<br>");
echo "<div id='group" . $oGroup->id . "' class='fb_group' />";
if($canRepeatGroup){

}
$oHtmlGroup->group_css = trim(str_replace($rubbish, "", $oGroup->group_css));
$oHtmlGroup->groupstyle = $oGroup->group_css;
if ( $oGroup->group_title != "" ) {
echo "<div class=\"fabrikgrouptitle\" id=\"title" . $oGroup->id . "\">".$oGroup->group_title."</div>\n";
}
$elsuffix = "";
$elpreffix = "";

if($canRepeatGroup == 1 && $oForm->_editable){
echo "<a href=\"javascript:duplicateGroup( $oGroup->id, '$addJs')\"> + Add</a>";
echo "<a href=\"javascript:deleteLastClone( $oGroup->id, '$delJs')\"> | Delete</a>";
echo "<div id='subgroup" . $oGroup->id . "_0' class='fb_sub_group' />";
$oHtmlGroup->displaystate = '1';
}else{
$oHtmlGroup->addlink ='';
$oHtmlGroup->dellink = '';
$oHtmlGroup->displaystate = '0';
}
//check if group is acutally a table join
if(array_key_exists($oGroup->id, $oForm->_aJoinGroupIds)){
$joinId = $oForm->_aJoinGroupIds[$oGroup->id];
//add in row id for join data
foreach($oForm->_table->_aJoins as $oJoin){
if($oJoin->id == $joinId){
$key = $oJoin->table_join_key;
if(array_key_exists('join', $data)){
$val = $data['join'][$joinId][$key];
}else{
$val = '';
}
echo '<input type="hidden" id="join.' . $joinId . '.rowid" name="join[' . $joinId . '][rowid]" value="' . $val . '" />';
}
}
}

foreach( $oGroup->_aElements as $oElement){
$parsed_name = $oGroup->getElementFullName( $oElement, $oForm, true, true);
$elementParams =& new fabrikParams( $oElement->attribs );
//set up the element names and ids
$elementHTMLName = $parsed_name;
$elementHTMLId = $oElement->getHTMLElementId();

if ( $oElement->elementtype_id == '2' && $oElement->password == "1" ) {
$aIgnoreOnUpdate[] = $parsed_name ;
}
if ( $oElement->elementtype_id == '8' ) {
$uploadCounter ++;
}
$aElement = array( );
$oElement->default = $oGroup->getElementDefaultValue( $oElement, $data, $oForm );
echo fabrik_html_content::getJavascript( $jsActions, $oElement->id );
if( $oForm->_editable ){
echo fabrik_html_content::getErrorMsg( $parsed_name, $arErrors, $oElement->elementtype_id );
}
echo fabrik_html_content::getCorrectLabel( $oForm, $oElement, $elementParams, $elementHTMLId );
echo fabrik_html_content::getElement( $oElement, $data, $arErrors, $js, $elementHTMLName, $elementParams, $lists, $uploadCounter, $rowId, $oForm->_editable, $elementHTMLId, $oForm );
}
if($canRepeatGroup){
echo "</div>";
}
//end of group div
echo "</div>";
}

echo "<input type='hidden' name='tableid' value='$tableId' class=''/>\n";
echo "<input type='hidden' name='fabrik' value='$oForm->id' class='' />\n";
echo "<input type='hidden' name='rowid' value='$rowId' class='' />\n";
echo "<input type='hidden' name='task' id='task' value='processForm' class='' />\n";
echo "<input type='hidden' name='option' value='com_fabrik' class='' />\n";
echo "<input type='hidden' name='form_id' value='".$oForm->id."' class='' />\n";
/*
* write in array of elements that dont get updated when the form is saved
* (could be password fields for eg that shouldnt get md5 hashed twice)
*/
$strignoreFields = implode(',', $aIgnoreOnUpdate);
echo "<input type='hidden' name='dontUpdateFields' value='".$strignoreFields."' class='' />\n";
echo ("<br style=\"clear:both;\" />\n");
echo ("</div>\n");
echo ("<div class=\"fabrikActions\">\n");
if ($oForm->reset_button == "1") {
echo "<input type=\"reset\" class=\"button\" name=\"Reset\" value=\"$oForm->reset_button_label\" />\n";
}
if ($oForm->submit_button_label != "") { // only show the submit button if it has a label
echo "<input type=\"submit\" class=\"button\" name=\"Submit\" value=\"$oForm->submit_button_label\" />\n ";
}
echo "</div>"; //end of fabrikactions div
echo "<br style=\"clear:both;\" />\n";
echo "</form>\n</div>\n";
$oForm->getBottomFormManagementJS();
}