alleyinteractive / alleyinteractive/wordpress-fieldmanager
`fm_added_element` event is triggered on proto element when Add More position is set to 'top'
- Ngôn ngữ chính
- PHP
- Star
- 563
- Fork
- 99
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## Expected Behavior
`fm_added_element` should fire on the newly-added element, making that available as `Event.target`.
## Actual Behavior
When I set `'add_more_position' => 'top'`, the `fm_added_element` event fires on the prototype element instead of the newly-added element.
This works as expected when using the default `'add_more_position' => 'bottom'`.
## Steps to Reproduce
Create a new `Fieldmanager_Group` with some children and set `'add_more_position' => 'top'`.
Load the following script somewhere:
```js
jQuery(document).ready(function($) {
$(document).on('fm_added_element', function(e) {
console.log(e.target);
});
});
```
Go to wherever you are displaying the group and add a new item.
Open your browser's developer tools console and note that the `fmjs-proto` class is present in the element's `classList`.
## Possible Solution
This is the problematic code:
https://github.com/alleyinteractive/wordpress-fieldmanager/blob/5213e079c9a5f5d11d78f6fc0dc1608af50d3743/js/fieldmanager.js#L161-L165
Specifically:
https://github.com/alleyinteractive/wordpress-fieldmanager/blob/5213e079c9a5f5d11d78f6fc0dc1608af50d3743/js/fieldmanager.js#L165
When `add_more_position == 'top'`, `.first()` should be used to find the new element instead of `.last()`.
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.