depends -> dependsOn

Hidden fields now retain their container div (hidden when empty)
This commit is contained in:
Samuel Georges 2015-01-29 20:32:24 +11:00
parent 569fe2e468
commit 167d113c12
9 changed files with 68 additions and 35 deletions

File diff suppressed because one or more lines are too long

View File

@ -95,6 +95,10 @@ label {
.form-group {
position: relative;
&:empty {
display: none;
}
&, &.layout-item {
padding-bottom: 20px;
margin-bottom: 0;
@ -526,7 +530,7 @@ label {
&.in-progress {
.select2-choice .select2-arrow {
display: none!important;
display: none !important;
}
}
}

View File

@ -55,7 +55,8 @@ html.cssanimations {
}
}
.loading-indicator-container.size-small .loading-indicator, .loading-indicator.size-small {
.loading-indicator.size-small,
.loading-indicator-container.size-small .loading-indicator {
padding: 16px 16px 16px 30px;
font-size: 11px;
& > span {

View File

@ -124,14 +124,18 @@ class FormController extends ControllerBehavior
$this->controller->formExtendFieldsBefore($this->formWidget);
});
$this->formWidget->bindEvent('form.extendFields', function () {
$this->controller->formExtendFields($this->formWidget);
$this->formWidget->bindEvent('form.extendFields', function ($fields) {
$this->controller->formExtendFields($this->formWidget, $fields);
});
$this->formWidget->bindEvent('form.beforeRefresh', function ($saveData) {
return $this->controller->formExtendRefreshData($this->formWidget, $saveData);
});
$this->formWidget->bindEvent('form.refreshFields', function ($fields) {
return $this->controller->formExtendRefreshFields($this->formWidget, $fields);
});
$this->formWidget->bindEvent('form.refresh', function ($result) {
return $this->controller->formExtendRefreshResults($this->formWidget, $result);
});
@ -623,7 +627,7 @@ class FormController extends ControllerBehavior
* @param Backend\Widgets\Form $host The hosting form widget
* @return void
*/
public function formExtendFields($host)
public function formExtendFields($host, $fields)
{
}
@ -637,6 +641,16 @@ class FormController extends ControllerBehavior
{
}
/**
* Called when the form is refreshed, giving the opportunity to modify the form fields.
* @param Backend\Widgets\Form $host The hosting form widget
* @param array $fields Current form fields
* @return array
*/
public function formExtendRefreshFields($host, $fields)
{
}
/**
* Called after the form is refreshed, should return an array of additional result parameters.
* @param Backend\Widgets\Form $host The hosting form widget

View File

@ -147,7 +147,7 @@ class FormField
/**
* @var array Other field names this field depends on, when the other fields are modified, this field will update.
*/
public $depends;
public $dependsOn;
/**
* Constructor.
@ -275,8 +275,12 @@ class FormField
if (isset($config['containerAttributes'])) {
$this->attributes($config['containerAttributes'], 'container');
}
if (isset($config['depends'])) {
$this->depends = $config['depends'];
if (isset($config['dependsOn'])) {
$this->dependsOn = $config['dependsOn'];
}
/* @deprecated remove if year >= 2016 */
elseif (isset($config['depends'])) {
$this->dependsOn = $config['depends'];
}
if (isset($config['path'])) {
$this->path = $config['path'];

View File

@ -285,7 +285,7 @@ class Form extends WidgetBase
*/
$eventResults = $this->fireEvent('form.beforeRefresh', [$saveData]) +
Event::fire('backend.form.beforeRefresh', [$this, $saveData]);
foreach ($eventResults as $eventResult) {
$saveData = $eventResult + $saveData;
}
@ -296,6 +296,12 @@ class Form extends WidgetBase
$this->setFormValues($saveData);
$this->prepareVars();
/*
* Extensibility
*/
$this->fireEvent('form.refreshFields', [$this->fields]);
Event::fire('backend.form.refreshFields', [$this, $this->fields]);
/*
* If an array of fields is supplied, update specified fields individually.
*/
@ -323,7 +329,7 @@ class Form extends WidgetBase
*/
$eventResults = $this->fireEvent('form.refresh', [$result]) +
Event::fire('backend.form.refresh', [$this, $result]);
foreach ($eventResults as $eventResult) {
$result = $eventResult + $result;
}
@ -380,8 +386,8 @@ class Form extends WidgetBase
/*
* Extensibility
*/
Event::fire('backend.form.extendFields', [$this]);
$this->fireEvent('form.extendFields');
$this->fireEvent('form.extendFields', [$this->fields]);
Event::fire('backend.form.extendFields', [$this, $this->fields]);
/*
* Convert automatic spanned fields
@ -724,13 +730,13 @@ class Form extends WidgetBase
*/
public function getFieldDepends($field)
{
if (!$field->depends) {
if (!$field->dependsOn) {
return;
}
$depends = is_array($field->depends) ? $field->depends : [$field->depends];
$depends = htmlspecialchars(json_encode($depends), ENT_QUOTES, 'UTF-8');
return $depends;
$dependsOn = is_array($field->dependsOn) ? $field->dependsOn : [$field->dependsOn];
$dependsOn = htmlspecialchars(json_encode($dependsOn), ENT_QUOTES, 'UTF-8');
return $dependsOn;
}
/**

View File

@ -3,6 +3,7 @@
<?php if ($depends = $this->getFieldDepends($field)): ?>data-field-depends="<?= $depends ?>"<?php endif ?>
data-field-name="<?= $field->fieldName ?>"
<?= $field->getAttributes('container') ?>
id="<?= $field->getId('group') ?>">
<?= $this->makePartial('field', ['field' => $field]) ?>
</div>
id="<?= $field->getId('group') ?>"><?=
/* Must be on the same line for :empty selector */
$this->makePartial('field', ['field' => $field])
?></div>

View File

@ -1,23 +1,27 @@
<?php if (in_array($field->type, ['checkbox', 'switch'])): ?>
<?php if (!$field->hidden): ?>
<?= $this->makePartial('field_'.$field->type, ['field' => $field]) ?>
<?php if (in_array($field->type, ['checkbox', 'switch'])): ?>
<?php else: ?>
<?= $this->makePartial('field_'.$field->type, ['field' => $field]) ?>
<?php if ($field->label): ?>
<label for="<?= $field->getId() ?>">
<?= e(trans($field->label)) ?>
</label>
<?php endif ?>
<?php else: ?>
<?php if ($field->comment && $field->commentPosition == 'above'): ?>
<p class="help-block before-field"><?= e(trans($field->comment)) ?></p>
<?php endif ?>
<?php if ($field->label): ?>
<label for="<?= $field->getId() ?>">
<?= e(trans($field->label)) ?>
</label>
<?php endif ?>
<?= $this->renderFieldElement($field) ?>
<?php if ($field->comment && $field->commentPosition == 'above'): ?>
<p class="help-block before-field"><?= e(trans($field->comment)) ?></p>
<?php endif ?>
<?= $this->renderFieldElement($field) ?>
<?php if ($field->comment && $field->commentPosition == 'below'): ?>
<p class="help-block"><?= e(trans($field->comment)) ?></p>
<?php endif ?>
<?php if ($field->comment && $field->commentPosition == 'below'): ?>
<p class="help-block"><?= e(trans($field->comment)) ?></p>
<?php endif ?>
<?php endif ?>

View File

@ -1,4 +1,3 @@
<?php foreach ($fields as $field): ?>
<?php if ($field->hidden) continue; ?>
<?= $this->makePartial('field-container', ['field' => $field]) ?>
<?php endforeach ?>