fix wpcfto select and repeater related visibility and validation

This commit is contained in:
dwindown
2025-08-29 19:27:50 +07:00
parent ccb2b1aea1
commit 255da46509
14 changed files with 495 additions and 233 deletions

View File

@@ -596,11 +596,6 @@ jQuery(function($){
}
}
$(document).on('change', '#customer_data select', function() {
var value = $(this).val();
$(this).attr('data-current-value', value);
});
$(document).on('click', '.delete-preview-field', function(e){
e.preventDefault();
$(this).parents('.preview-field').remove();
@@ -760,40 +755,40 @@ jQuery(function($){
$(this).closest('.child-field-title').toggleClass('option-detail-opened');
});
var all_checkbox = $('[type="checkbox"]');
if(all_checkbox.length > 0){
$.each(all_checkbox, function(a,b){
if($(b).val() == 'yes'){
$(b).val('no').trigger('click');
}
});
}
// var all_checkbox = $('[type="checkbox"]');
// if(all_checkbox.length > 0){
// $.each(all_checkbox, function(a,b){
// if($(b).val() == 'yes'){
// $(b).val('no').trigger('click');
// }
// });
// }
function modify_payment_box_behavior() {
// function modify_payment_box_behavior() {
var allbox = $('#payments multi_checkbox');
var checkbox_input = $('.payments-payment input[type=checkbox]');
var checked_value = [];
if(checkbox_input.length > 0){
$.each(checkbox_input, function(x, y){
if($(y).is(':checked')){
checked_value.push($(y).val());
$('[data-field=wpcfto_addon_option_payment_'+$(y).val()+']').show();
}else{
$('[data-field=wpcfto_addon_option_payment_'+$(y).val()+']').hide();
}
});
}
// var allbox = $('#payments multi_checkbox');
// var checkbox_input = $('.payments-payment input[type=checkbox]');
// var checked_value = [];
// if(checkbox_input.length > 0){
// $.each(checkbox_input, function(x, y){
// if($(y).is(':checked')){
// checked_value.push($(y).val());
// $('[data-field=wpcfto_addon_option_payment_'+$(y).val()+']').show();
// }else{
// $('[data-field=wpcfto_addon_option_payment_'+$(y).val()+']').hide();
// }
// });
// }
}
// }
setTimeout(() => {
modify_payment_box_behavior();
}, 500);
// setTimeout(() => {
// modify_payment_box_behavior();
// }, 500);
$(document).on('click', '.payments-payment input[type=checkbox]', function(){
modify_payment_box_behavior();
});
// $(document).on('click', '.payments-payment input[type=checkbox]', function(){
// modify_payment_box_behavior();
// });
$(document).on('mouseover', 'span.grab', function(){
$(this).css('pointer', 'grab');
@@ -807,9 +802,14 @@ jQuery(function($){
$(this).closest('.child-fields-wrapper').find('.the_title').text($(this).val());
});
$(document).on('change', '#customer_data select', function() {
var value = $(this).val();
$(this).attr('data-current-value', value);
});
});
jQuery(function($){
// jQuery(function($){
// setTimeout(() => {
// var autocomplete_fields = $('.wpcfto-box .autocomplete');
@@ -831,116 +831,116 @@ jQuery(function($){
// }, 500);
// });
$( document ).on( 'click', '.add-thumbnail', function( event ) {
// $( document ).on( 'click', '.add-thumbnail', function( event ) {
var gallery_items_frame;
const $el = $( this );
var target_field = $el.attr('data-field');
var target_id = $el.siblings('.'+target_field+'-id');
var target_url = $el.siblings('.'+target_field+'-url');
var selected = target_id.val();
var able_multiple = $el.attr('data-able-multiple');
// var gallery_items_frame;
// const $el = $( this );
// var target_field = $el.attr('data-field');
// var target_id = $el.siblings('.'+target_field+'-id');
// var target_url = $el.siblings('.'+target_field+'-url');
// var selected = target_id.val();
// var able_multiple = $el.attr('data-able-multiple');
event.preventDefault();
// event.preventDefault();
if ( gallery_items_frame ) {
// if ( gallery_items_frame ) {
// Select the attachment when the frame opens
gallery_items_frame.on( 'open', function() {
var selection = gallery_items_frame.state().get( 'selection' );
selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
});
// // Select the attachment when the frame opens
// gallery_items_frame.on( 'open', function() {
// var selection = gallery_items_frame.state().get( 'selection' );
// selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
// });
// Open the modal.
gallery_items_frame.open();
// // Open the modal.
// gallery_items_frame.open();
return;
}
// return;
// }
// Create the media frame.
gallery_items_frame = wp.media.frames.gallery_items = wp.media({
// Set the title of the modal.
title: 'Choose or upload media',
button: {
text: 'Select'
},
states: [
new wp.media.controller.Library({
title: 'Choose or upload media',
filterable: 'all',
multiple: able_multiple
})
]
});
// // Create the media frame.
// gallery_items_frame = wp.media.frames.gallery_items = wp.media({
// // Set the title of the modal.
// title: 'Choose or upload media',
// button: {
// text: 'Select'
// },
// states: [
// new wp.media.controller.Library({
// title: 'Choose or upload media',
// filterable: 'all',
// multiple: able_multiple
// })
// ]
// });
// Select the attachment when the frame opens
gallery_items_frame.on( 'open', function() {
var selection = gallery_items_frame.state().get( 'selection' );
selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
});
// // Select the attachment when the frame opens
// gallery_items_frame.on( 'open', function() {
// var selection = gallery_items_frame.state().get( 'selection' );
// selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
// });
gallery_items_frame.on( 'select', function() {
attachment = gallery_items_frame.state().get('selection').first().toJSON();
target_id.val( attachment.id );
target_url.val( attachment.url );
if(target_id.val() !== ''){
// $el.removeClass('text-white').addClass('text-info d-none');
if($el.hasClass('btn')){
$el.siblings('i').hide();
}else{
$el.hide();
}
$el.siblings('img').removeClass('d-none').attr('src', attachment.url).show();
}else{
// $el.removeClass('text-info d-none').addClass('text-white');
if($el.hasClass('btn')){
$el.siblings('i').show();
}else{
$el.show();
}
$el.siblings('img').addClass('d-none').hide();
}
});
// gallery_items_frame.on( 'select', function() {
// attachment = gallery_items_frame.state().get('selection').first().toJSON();
// target_id.val( attachment.id );
// target_url.val( attachment.url );
// if(target_id.val() !== ''){
// // $el.removeClass('text-white').addClass('text-info d-none');
// if($el.hasClass('btn')){
// $el.siblings('i').hide();
// }else{
// $el.hide();
// }
// $el.siblings('img').removeClass('d-none').attr('src', attachment.url).show();
// }else{
// // $el.removeClass('text-info d-none').addClass('text-white');
// if($el.hasClass('btn')){
// $el.siblings('i').show();
// }else{
// $el.show();
// }
// $el.siblings('img').addClass('d-none').hide();
// }
// });
// Open the modal.
gallery_items_frame.open();
// // Open the modal.
// gallery_items_frame.open();
});
// });
$( document ).on( 'click', '.trumbowyg-button-group:has(.trumbowyg-insertImage-button)', function( event ) {
// $( document ).on( 'click', '.trumbowyg-button-group:has(.trumbowyg-insertImage-button)', function( event ) {
var gallery_items_frame;
// var gallery_items_frame;
event.preventDefault();
// event.preventDefault();
// Create the media frame.
gallery_items_frame = wp.media.frames.gallery_items = wp.media({
// Set the title of the modal.
title: 'Choose or upload media',
button: {
text: 'Select'
},
states: [
new wp.media.controller.Library({
title: 'Choose or upload media',
filterable: 'all',
multiple: false
})
]
});
// // Create the media frame.
// gallery_items_frame = wp.media.frames.gallery_items = wp.media({
// // Set the title of the modal.
// title: 'Choose or upload media',
// button: {
// text: 'Select'
// },
// states: [
// new wp.media.controller.Library({
// title: 'Choose or upload media',
// filterable: 'all',
// multiple: false
// })
// ]
// });
gallery_items_frame.on( 'select', function() {
attachment = gallery_items_frame.state().get('selection').first().toJSON();
var target_input_url = $('.trumbowyg-modal.trumbowyg-fixed-top .trumbowyg-input-html input');
var target_confirm = $('.trumbowyg-modal.trumbowyg-fixed-top .trumbowyg-modal-submit');
target_input_url.val( attachment.url );
target_confirm.trigger('click');
// gallery_items_frame.on( 'select', function() {
// attachment = gallery_items_frame.state().get('selection').first().toJSON();
// var target_input_url = $('.trumbowyg-modal.trumbowyg-fixed-top .trumbowyg-input-html input');
// var target_confirm = $('.trumbowyg-modal.trumbowyg-fixed-top .trumbowyg-modal-submit');
// target_input_url.val( attachment.url );
// target_confirm.trigger('click');
});
// });
// Open the modal.
gallery_items_frame.open();
// // Open the modal.
// gallery_items_frame.open();
});
// });
});
// });