Skip to content

Commit

Permalink
Attempting to fix issue with defaulting dates in new groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesegrits committed Nov 25, 2015
1 parent 550863f commit a046668
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion components/com_fabrik/models/element.php
Expand Up @@ -163,6 +163,16 @@ class PlgFabrik_Element extends FabrikPlugin
*/
public $inRepeatGroup = null;

/**
* Is the element in a new group.
*
* Used by pre rendering / getGroupView so elements can set a default on new repeat groups,
* even if it isn't a new record.
*
* @var bool
*/
public $newGroup = null;

/**
* Default value
*
Expand Down Expand Up @@ -7175,7 +7185,7 @@ public function onFinalStoreRow(&$data)
if (get_class($this) === 'PlgFabrik_ElementFileupload' && $ajaxSubmit)
{
$allParams = array_key_exists('crop', $joinValues) ? array_values($joinValues['crop']) : array();
$joinValues = array_key_exists('id', $joinValues) ? array_keys($joinValues['id']) : array();
$joinValues = array_key_exists('id', $joinValues) ? array_keys($joinValues['id']) : $joinValues;
}

foreach ($joinValues as $jIndex => $jid)
Expand Down
10 changes: 10 additions & 0 deletions components/com_fabrik/models/form.php
Expand Up @@ -4562,6 +4562,7 @@ public function getGroupView($tmpl = '')
$repeatGroup = 1;
$foreignKey = null;
$startHidden = false;
$newGroup = false;

if ($groupModel->canRepeat())
{
Expand All @@ -4572,6 +4573,12 @@ public function getGroupView($tmpl = '')
{
$repeatGroup = $groupModel->repeatCount();

if ($repeatGroup === 0)
{
$newGroup = true;
$repeatGroup = 1;
}

if (!$groupModel->fkPublished())
{
$startHidden = false;
Expand All @@ -4590,6 +4597,8 @@ public function getGroupView($tmpl = '')
$repeatGroup = 1;
$startHidden = true;
}

$newGroup = false;
}

$groupModel->repeatTotal = $startHidden ? 0 : $repeatGroup;
Expand All @@ -4608,6 +4617,7 @@ public function getGroupView($tmpl = '')
*/
$elementModel->setFormModel($this);
$elementModel->tmpl = $tmpl;
$elementModel->newGroup = $newGroup;

/* $$$rob test don't include the element in the form is we can't use and edit it
* test for captcha element when user logged in
Expand Down
2 changes: 1 addition & 1 deletion components/com_fabrik/models/group.php
Expand Up @@ -1548,7 +1548,7 @@ public function repeatCount()
if (!empty($elementModels))
{
$smallerElHTMLName = $tmpElement->getFullName(true, false);
$d = FArrayHelper::getValue($data, $smallerElHTMLName, 1);
$d = FArrayHelper::getValue($data, $smallerElHTMLName, array());

if (is_object($d))
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/fabrik_element/date/date.php
Expand Up @@ -1028,7 +1028,7 @@ public function getValue($data, $repeatCounter = 0, $opts = array())
$shortNullDate = FArrayHelper::getValue($shortNullDate, 0);
$isNullDate = $nullDate == $value || $shortNullDate == $value;

if (!($formModel->isNewRecord() && $defaultToday) && $value == '')
if (!(($formModel->isNewRecord() || $this->newGroup) && $defaultToday) && $value == '')
{
if (($value == '' || $isNullDate) && !$alwaysToday)
{
Expand Down

0 comments on commit a046668

Please sign in to comment.