-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (53 loc) · 2.67 KB
/
script.js
File metadata and controls
54 lines (53 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function customTriggerChangeEvent(element) {
const customChangeEvent = new Event("change");
element.dispatchEvent(customChangeEvent);
};
var Webflow = Webflow || [];
Webflow.push(function () {
/* Ignore Inputs Functions */
$("form").submit(function() {
$('[data-submit="ignore"]').replaceWith(function(){
return $("<div>", {html: $(this).html(), class: $(this).attr('class')});
});
});
$('[tf-custom-select-option-value]').attr('data-submit', 'ignore');
/* Custom Dropdown Select Functions */
$('[tf-custom-select-wrapper]').each(function(index, item) {
const isMultipleSelect = item.hasAttribute("tf-custom-select-multiple");
const $currentWrapper = $(this);
const $currentDropdown = $(this).find('.w-dropdown');
const $currentDropdownResultElement = $(this).find('[tf-custom-select-result]');
const $currentHiddenInput = $(this).find('[tf-custom-select-input]');
const $currentPlaceHolderElement = $currentDropdownResultElement.html();
$currentHiddenInput.attr('tabindex', '-1')
$(this).find('[tf-custom-select-option-value]').on("click", function () {
if(isMultipleSelect){
let selectedValuesList = [];
let selectedOptionsElements = [];
$(this).toggleClass('active');
$currentWrapper.find('.active[tf-custom-select-option-value]').each(function () {
selectedValuesList.push($(this).attr('tf-custom-select-option-value'));
selectedOptionsElements.push($(this).html());
});
$currentHiddenInput.val(selectedValuesList);
customTriggerChangeEvent($currentHiddenInput.get(0));
if($currentDropdownResultElement.length > 0) {
$currentDropdownResultElement.html('');
if(selectedOptionsElements.length > 0){
selectedOptionsElements.map((selectedOptionsElement)=>{
$currentDropdownResultElement.append(selectedOptionsElement);
})
}else{
$currentDropdownResultElement.html($currentPlaceHolderElement);
}
}
}else{
$(this).siblings().removeClass('active');
$(this).addClass('active');
if($currentDropdownResultElement.length > 0) $currentDropdownResultElement.html($(this).html());
$currentHiddenInput.val($(this).attr('tf-custom-select-option-value'));
}
if($currentDropdown.length > 0) $currentDropdown.trigger('w-close');
});
});
})