Fix the input trigger API where a form element doesn't exist (#4033)

There are no `form` elements in the preview context of a form, so this adds an alternative selector to use when no common `form` elements are found for the Input Trigger API to use. Credit to @fansaien
This commit is contained in:
fansaien 2019-01-03 16:24:43 -06:00 committed by Luke Towers
parent d6b1b6e95d
commit 2dcd84c4f2
2 changed files with 12 additions and 4 deletions

View File

@ -511,7 +511,7 @@ class FormField
'data-trigger' => '[name="'.$fullTriggerField.'"]', 'data-trigger' => '[name="'.$fullTriggerField.'"]',
'data-trigger-action' => $triggerAction, 'data-trigger-action' => $triggerAction,
'data-trigger-condition' => $triggerCondition, 'data-trigger-condition' => $triggerCondition,
'data-trigger-closest-parent' => 'form' 'data-trigger-closest-parent' => 'form, div[data-control="formwidget"]'
]; ];
return $attributes + $newAttributes; return $attributes + $newAttributes;

View File

@ -28,9 +28,17 @@
this.triggerConditionValue = (match) ? match : [""] this.triggerConditionValue = (match) ? match : [""]
} }
this.triggerParent = this.options.triggerClosestParent !== undefined this.triggerParent = undefined
? $el.closest(this.options.triggerClosestParent) if (this.options.triggerClosestParent !== undefined) {
: undefined var closestParentElements = this.options.triggerClosestParent.split(',')
for (var i = 0; i < closestParentElements.length; i++) {
var $triggerElement = $el.closest(closestParentElements[i])
if ($triggerElement.length) {
this.triggerParent = $triggerElement
break
}
}
}
if ( if (
this.triggerCondition == 'checked' || this.triggerCondition == 'checked' ||