survey/app/assets/javascripts/trigger_option.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-07-08 13:31:27 +00:00
function get_uniq(arr){
return arr.filter(function (value, index, self) {
return self.indexOf(value) === index;
})
}
$(document).on('ready',function() {
var $target
$target = $('.select_trigger')
var change_eles = []
$.each($target,function(){
var e = $(this).attr('data-trigger'),
p = $(this).attr('data-parent'),
ele = $(this).parents(p).eq(0).find(e),
trigger_keys = $(this).attr('for').split('|'),
$this = $(this);
if (!change_eles.includes(ele[0])){
change_eles.push(ele[0])
ele.off('change')
}
ele.change(function(){
var value = null;
if ($(this).prop("tagName").toUpperCase()=='INPUT'){
value = $(this).filter(":checked").val()
}else{
value = $(this).val()
}
if (trigger_keys.includes(value)){
$this.removeClass('hide')
}else{
$this.addClass('hide')
}
}).trigger('change')
})
$target = $('input[data-div]');
$target.off('change')
$target.change(function(){
var $child = $(this).parents('div.attributes-body').eq(0).find('.'+$(this).data('div'))
if ($(this).prop('checked')){
$child.removeClass('hide')
}else{
$child.addClass('hide')
}
})
$target.trigger('change')
$target.parents('label.float-right').css('float','right')
})
$(function(){
$(document).trigger('ready')
})