mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Merge pull request #2235 from acasar/nested-depends-on
DependsOn in repeater
This commit is contained in:
commit
07b0c7d0ce
@ -158,4 +158,12 @@ class Repeater extends FormWidgetBase
|
||||
// Useful for deleting relations
|
||||
}
|
||||
|
||||
public function onRefresh()
|
||||
{
|
||||
$index = post('_index');
|
||||
|
||||
$widget = $this->makeItemFormWidget($index);
|
||||
|
||||
return $widget->onRefresh();
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,8 @@
|
||||
<a
|
||||
href="javascript:;"
|
||||
data-load-indicator
|
||||
data-request="<?= $this->getEventHandler('onAddItem') ?>">
|
||||
data-request="<?= $this->getEventHandler('onAddItem') ?>"
|
||||
data-request-success="$('#<?= $this->getId('items') ?> .field-repeater-form:last').formWidget()">
|
||||
<?= e(trans($prompt)) ?>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -17,7 +17,10 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="field-repeater-form">
|
||||
<div class="field-repeater-form"
|
||||
data-control="formwidget"
|
||||
data-refresh-handler="<?= $this->getEventHandler('onRefresh') ?>"
|
||||
data-refresh-data='{"_index": "<?= $indexValue ?>"}'>
|
||||
<?php foreach ($widget->getFields() as $field): ?>
|
||||
<?= $widget->renderField($field) ?>
|
||||
<?php endforeach ?>
|
||||
|
@ -77,12 +77,13 @@
|
||||
FormWidget.prototype.bindDependants = function() {
|
||||
var self = this,
|
||||
form = this.$el,
|
||||
fieldMap = {}
|
||||
fieldMap = {},
|
||||
nestedDependencies = form.find('[data-control="formwidget"] [data-field-depends]');
|
||||
|
||||
/*
|
||||
* Map master and slave fields
|
||||
*/
|
||||
form.find('[data-field-depends]').each(function() {
|
||||
form.find('[data-field-depends]').not(nestedDependencies).each(function() {
|
||||
var name = $(this).data('field-name'),
|
||||
depends = $(this).data('field-depends')
|
||||
|
||||
@ -100,6 +101,8 @@
|
||||
$.each(fieldMap, function(fieldName, toRefresh){
|
||||
form
|
||||
.find('[data-field-name="'+fieldName+'"]')
|
||||
// Exclude nested formwidget elements
|
||||
.not(form.find('[data-control="formwidget"] [data-field-name="'+fieldName+'"]'))
|
||||
.on('change.oc.formwidget', $.proxy(self.onRefreshDependants, self, fieldName, toRefresh))
|
||||
})
|
||||
}
|
||||
@ -119,7 +122,7 @@
|
||||
|
||||
this.dependantUpdateTimers[fieldName] = window.setTimeout(function() {
|
||||
formEl.request(self.options.refreshHandler, {
|
||||
data: toRefresh
|
||||
data: $.extend({}, toRefresh, form.data('refresh-data'))
|
||||
}).success(function() {
|
||||
self.toggleEmptyTabs()
|
||||
})
|
||||
@ -127,6 +130,8 @@
|
||||
|
||||
$.each(toRefresh.fields, function(index, field) {
|
||||
form.find('[data-field-name="'+field+'"]:visible')
|
||||
// Exclude nested formwidget elements
|
||||
.not(form.find('[data-control="formwidget"] [data-field-name="'+field+'"]:visible'))
|
||||
.addClass('loading-indicator-container size-form-field')
|
||||
.loadIndicator()
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user