PHP - Problema Checkbox - Marcar - Desmarcar

 
Vista:
sin imagen de perfil
Val: 12
Ha aumentado su posición en 15 puestos en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por oscar (4 intervenciones) el 20/04/2021 23:02:23
Hola, este es el enlace a uno de los productos de mi web https://www.boomboombrunch.com/product/terreta/, tengo un problema con el apartado checkbox, tengo establecido un número límite de opciones para seleccionar pero cuando seleccionan esa cantidad límite se bloquean todas las casillas y no me deja desmarcar ninguna de las opciones anteriores, alguien podría ayudarme?
Captura-de-pantalla-2021-04-20-a-las-22.58.33
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por joel (1269 intervenciones) el 21/04/2021 07:59:47
Hola Oscar, eso lo estarás controlando tu desde JavaScript... por alguna razón, una vez seleccionas un checkbox, te añade el disabled para no poder modificar-lo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 12
Ha aumentado su posición en 15 puestos en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por oscar (4 intervenciones) el 21/04/2021 09:49:08
Y como debería de estar? en caso de que elimine la opción disabled
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por joel (1269 intervenciones) el 21/04/2021 10:14:44
No entiendo muy bien tu pregunta Oscar... tu lo has tenido que poner en el código, no??? por defecto no se desactiva un check cuando se selecciona.
o es un código copiado o un plugin, o algo por el estilo?

faltaría ver el código javascript...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 12
Ha aumentado su posición en 15 puestos en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por oscar (4 intervenciones) el 21/04/2021 10:36:27
Exacto, es un plugin con codigo Javascript
Captura-de-pantalla-2021-04-21-a-las-10.22.02
Captura-de-pantalla-2021-04-21-a-las-10.22.35

Aquí copio el código:

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
jQuery( document ).ready( function($) {
 
	$.fn.init_addon_totals = function() {
 
		function isGroupedMixedProductType() {
			var group  = $( '.product-type-grouped' ),
				subs   = 0,
				simple = 0;
 
			if ( group.length ) {
				group.find( '.group_table tr.product' ).each( function() {
					if ( 0 < $( this ).find( '.input-text.qty' ).val() ) {
						// For now only checking between simple and subs.
						if ( $( this ).find( '.entry-summary .subscription-details' ).length ) {
							subs++;
						} else {
							simple++;
						}
					}
				});
 
				if ( 0 < subs && 0 < simple ) {
					return true;
				}
			}
 
			return false;
		}
 
		function isGroupedSubsSelected() {
			var group = $( '.product-type-grouped' ),
				subs  = false;
 
			if ( group.length ) {
				group.find( '.group_table tr.product' ).each( function() {
					if ( 0 < $( this ).find( '.input-text.qty' ).val() ) {
						if ( $( this ).find( '.entry-summary .subscription-details' ).length ) {
							subs = true;
							return false;
						}
					}
				});
			}
 
			return subs;
		}
 
		var $cart            = $( this ),
			$variation_input = $cart.hasClass( 'variations_form' ) ? $cart.find( 'input[name="variation_id"], input.variation_id' ) : false;
 
		// Clear all values on variable product when clear selection is clicked
		$( this ).on( 'click', '.reset_variations', function() {
 
			$.each( $cart.find( '.product-addon' ), function() {
				var element = $( this ).find( '.addon' );
 
				if ( element.is( ':checkbox' ) || element.is( ':radio' ) ) {
					element.prop( 'checked', false );
				}
 
				if ( element.is( 'select' ) ) {
					element.prop( 'selectedIndex', 0 );
				}
 
				if ( element.is( ':text' ) || element.is( 'textarea' ) || element.is( 'input[type="number"]' ) || element.is( 'input[type="file"]' ) ) {
					element.val( '' );
				}
			});
 
			$cart.trigger( 'lafka-product-addons-update' );
		});
 
		// clicking on a number input scrollers updates the total continuously.
		$( this ).on( 'mouseup', 'input[type=number]', function (e) {
			$( this ).trigger( 'lafka-product-addons-update' );
		});
 
		$( this ).on( 'keyup change', '.product-addon input, .product-addon textarea', function() {
 
			if ( $( this ).attr( 'maxlength' ) > 0 ) {
 
				var value     = $( this ).val();
				var remaining = $( this ).attr( 'maxlength' ) - value.length;
 
				$( this ).next( '.chars_remaining' ).find( 'span' ).text( remaining );
			}
 
		});
 
		$(this).on('change', '.product-addon.lafka-limit input', function () {
			var $inputsContainer = $(this).parents('.product-addon');
			var limit = parseInt($inputsContainer.data('addon-group-limit'));
			var total_checked = $inputsContainer.find('input[name="' + $(this).attr('name') + '"]:checked').length;
 
			if (limit <= total_checked) {
				$inputsContainer.find('input').each(function (index, element) {
					if (!$(this).attr('checked')) {
						$(this).attr('disabled', true);
					}
				});
			} else {
				$inputsContainer.find('input').each(function (index, element) {
					$(this).removeAttr('disabled');
				});
			}
		});
 
		$( this ).find( ' .addon-custom, .addon-custom-textarea' ).each( function() {
 
			if ( $( this ).attr( 'maxlength' ) > 0 ) {
 
				$( this ).after( '<small class="chars_remaining"><span>' + $( this ).attr( 'maxlength' ) + '</span> ' + lafka_addons_params.i18n_remaining + '</small>' );
 
			}
 
		});
 
		$( this ).on( 'change', '.product-addon input, .product-addon textarea, .product-addon select, input.qty', function() {
 
			$( this ).trigger( 'lafka-product-addons-update' );
		});
 
		$( this ).on( 'found_variation', function( event, variation ) {
 
			var $variation_form = $( this ),
				$totals         = $variation_form.find( '#product-addons-total' );
 
			if ( typeof( variation.display_price ) !== 'undefined' ) {
 
				$totals.data( 'price', variation.display_price );
 
			} else if ( $( variation.price_html ).find( '.amount:last' ).size() ) {
 
				product_price = $( variation.price_html ).find( '.amount:last' ).text();
				product_price = product_price.replace( lafka_addons_params.currency_format_symbol, '' );
				product_price = product_price.replace( lafka_addons_params.currency_format_thousand_sep, '' );
				product_price = product_price.replace( lafka_addons_params.currency_format_decimal_sep, '.' );
				product_price = product_price.replace(/[^0-9\.]/g, '' );
				product_price = parseFloat( product_price );
 
				$totals.data( 'price', product_price );
			}
 
			$variation_form.trigger( 'lafka-product-addons-update' );
		});
 
		// Compatibility with Smart Coupons self declared gift amount purchase.
		var custom_gift_card_amount = $( '#credit_called' );
 
		$( custom_gift_card_amount ).on( 'keyup', function() {
			$cart.trigger( 'lafka-product-addons-update' );
		});
 
		$( this ).on( 'lafka-product-addons-update', function() {
			var total         = 0,
				total_raw     = 0,
				$totals       = $cart.find( '#product-addons-total' ),
				is_variable   = $variation_input && $variation_input.length > 0,
				product_id    = is_variable ? $variation_input.val() : $totals.data( 'product-id' ),
				product_price = $totals.data( 'price' ),
				product_type  = $totals.data( 'type' ),
				qty           = $cart.find( '.quantity .qty' ).val();
 
			// Compatibility with Smart Coupons self declared gift amount purchase.
			if ( '' === product_price && custom_gift_card_amount.length && 0 < custom_gift_card_amount.val() ) {
				product_price = custom_gift_card_amount.val();
			}
 
			$cart.find( '.addon' ).each( function() {
				var addon_cost     = 0,
					addon_cost_raw = 0;
 
				if ( $( this ).is( '.addon-custom-price' ) ) {
					addon_cost = $( this ).val();
				} else if ( $( this ).is( '.addon-input_multiplier' ) ) {
					if( isNaN( $( this ).val() ) || $( this ).val() == "" ) { // Number inputs return blank when invalid
						$( this ).val( '' );
						$( this ).closest( 'p' ).find( '.addon-alert' ).show();
					} else {
						if( $( this ).val() != "" ){
							$( this ).val( Math.ceil( $( this ).val() ) );
						}
						$( this ).closest( 'p' ).find( '.addon-alert' ).hide();
					}
					addon_cost     = $( this ).data( 'price' ) * $( this ).val();
					addon_cost_raw = $( this ).data( 'raw-price' ) * $( this ).val();
				} else if ( $( this ).is( '.addon-checkbox, .addon-radio' ) ) {
					if ( $( this ).is( ':checked' ) ) {
						addon_cost     = $( this ).data( 'price' );
						addon_cost_raw = $( this ).data( 'raw-price' );
					}
				} else if ( $( this ).is( '.addon-select' ) ) {
					if ( $( this ).val() ) {
						addon_cost     = $( this ).find( 'option:selected' ).data( 'price' );
						addon_cost_raw = $( this ).find( 'option:selected' ).data( 'raw-price' );
					}
				} else {
					if ( $( this ).val() ) {
						addon_cost     = $( this ).data( 'price' );
						addon_cost_raw = $( this ).data( 'raw-price' );
					}
				}
 
				if ( ! addon_cost ) {
					addon_cost = 0;
				}
				if ( ! addon_cost_raw ) {
					addon_cost_raw = 0;
				}
 
				total = parseFloat( total ) + parseFloat( addon_cost );
				total_raw = parseFloat( total_raw ) + parseFloat( addon_cost_raw );
			} );
 
			$totals.data( 'addons-price', total );
			$totals.data( 'addons-raw-price', total_raw );
 
			if ( $cart.find( 'input.qty' ).size() ) {
				var qty = 0;
 
				$cart.find( 'input.qty' ).each( function() {
					qty += parseFloat( $( this ).val() );
				});
			} else {
				var qty = 1;
			}
 
			if ( total > 0 && qty > 0 ) {
 
				var product_total_price,
					subscription_details = false;
 
				total     = parseFloat( total * qty );
				total_raw = parseFloat( total_raw * qty );
 
				var formatted_addon_total = accounting.formatMoney( total, {
					symbol 		: lafka_addons_params.currency_format_symbol,
					decimal 	: lafka_addons_params.currency_format_decimal_sep,
					thousand	: lafka_addons_params.currency_format_thousand_sep,
					precision 	: lafka_addons_params.currency_format_num_decimals,
					format		: lafka_addons_params.currency_format
				});
 
				if ( 'undefined' !== typeof product_price && product_id ) {
 
					product_total_price = parseFloat( product_price * qty );
 
					var formatted_sub_total = accounting.formatMoney( product_total_price + total, {
						symbol 		: lafka_addons_params.currency_format_symbol,
						decimal 	: lafka_addons_params.currency_format_decimal_sep,
						thousand	: lafka_addons_params.currency_format_thousand_sep,
						precision 	: lafka_addons_params.currency_format_num_decimals,
						format		: lafka_addons_params.currency_format
					});
				}
 
				if ( $( '.entry-summary .subscription-details' ).length ) {
					// Add-Ons added at bundle level only affect the up-front price.
					if ( ! $cart.hasClass( 'bundle_data' ) ) {
						subscription_details = $( '.entry-summary .subscription-details' ).clone().wrap( '<p>' ).parent().html();
					}
				}
 
				if ( 'grouped' === product_type ) {
					if ( subscription_details && ! isGroupedMixedProductType() && isGroupedSubsSelected() ) {
						formatted_addon_total += subscription_details;
						if ( formatted_sub_total ) {
							formatted_sub_total += subscription_details;
						}
					}
				} else if ( subscription_details ) {
					formatted_addon_total += subscription_details;
					if ( formatted_sub_total ) {
						formatted_sub_total += subscription_details;
					}
				}
 
				var html = '<dl class="product-addon-totals"><dt>' + lafka_addons_params.i18n_addon_total + '</dt><dd><strong><span class="amount">' + formatted_addon_total + '</span></strong></dd>';
 
				if ( formatted_sub_total && '1' == $totals.data( 'show-sub-total' ) ) {
 
					// To show our "price display suffix" we have to do some magic since the string can contain variables (excl/incl tax values)
					// so we have to take our sub total and find out what the tax value is, which we can do via an ajax call
					// if its a simple string, or no string at all, we can output the string without an extra call
					var price_display_suffix = '',
						sub_total_string     = typeof( $totals.data( 'i18n_sub_total' ) ) === 'undefined' ? lafka_addons_params.i18n_sub_total : $totals.data( 'i18n_sub_total' );
 
					// no sufix is present, so we can just output the total
					if ( ! lafka_addons_params.price_display_suffix ) {
						html = html + '<dt>' + sub_total_string + '</dt><dd><strong><span class="amount">' + formatted_sub_total + '</span></strong></dd></dl>';
						$totals.html( html );
						$cart.trigger( 'updated_addons' );
						return;
					}
 
					// a suffix is present, but no special labels are used - meaning we don't need to figure out any other special values - just display the playintext value
					if ( false === ( lafka_addons_params.price_display_suffix.indexOf( '{price_including_tax}' ) > -1 ) && false === ( lafka_addons_params.price_display_suffix.indexOf( '{price_excluding_tax}' ) > -1 ) ) {
						html = html + '<dt>' + sub_total_string + '</dt><dd><strong><span class="amount">' + formatted_sub_total + '</span> ' + lafka_addons_params.price_display_suffix + '</strong></dd></dl>';
						$totals.html( html );
						$cart.trigger( 'updated_addons' );
						return;
					}
 
					// Based on the totals/info and settings we have, we need to use the get_price_*_tax functions
					// to get accurate totals. We can get these values with a special Ajax function
					$.ajax( {
						type: 'POST',
						url:  lafka_addons_params.ajax_url,
						data: {
							action: 'wc_product_addons_calculate_tax',
							product_id: product_id,
							add_on_total: total,
							add_on_total_raw: total_raw,
							qty: qty
						},
						success: 	function( result ) {
							if ( result.result == 'SUCCESS' ) {
								price_display_suffix = '<small class="woocommerce-price-suffix">' + lafka_addons_params.price_display_suffix + '</small>';
								var formatted_price_including_tax = accounting.formatMoney( result.price_including_tax, {
									symbol 		: lafka_addons_params.currency_format_symbol,
									decimal 	: lafka_addons_params.currency_format_decimal_sep,
									thousand	: lafka_addons_params.currency_format_thousand_sep,
									precision 	: lafka_addons_params.currency_format_num_decimals,
									format		: lafka_addons_params.currency_format
								} );
								var formatted_price_excluding_tax = accounting.formatMoney( result.price_excluding_tax, {
									symbol 		: lafka_addons_params.currency_format_symbol,
									decimal 	: lafka_addons_params.currency_format_decimal_sep,
									thousand	: lafka_addons_params.currency_format_thousand_sep,
									precision 	: lafka_addons_params.currency_format_num_decimals,
									format		: lafka_addons_params.currency_format
								} );
								price_display_suffix = price_display_suffix.replace( '{price_including_tax}', formatted_price_including_tax );
								price_display_suffix = price_display_suffix.replace( '{price_excluding_tax}', formatted_price_excluding_tax );
								html                 = html + '<dt>' + sub_total_string + '</dt><dd><strong><span class="amount">' + formatted_sub_total + '</span> ' + price_display_suffix + ' </strong></dd></dl>';
								$totals.html( html );
								$cart.trigger( 'updated_addons' );
							} else {
								html = html + '<dt>' + sub_total_string + '</dt><dd><strong><span class="amount">' + formatted_sub_total + '</span></strong></dd></dl>';
								$totals.html( html );
								$cart.trigger( 'updated_addons' );
							}
						},
						error: function() {
							html = html + '<dt>' + sub_total_string + '</dt><dd><strong><span class="amount">' + formatted_sub_total + '</span></strong></dd></dl>';
							$totals.html( html );
							$cart.trigger( 'updated_addons' );
						}
					});
				} else {
					$totals.empty();
					$cart.trigger( 'updated_addons' );
				}
			} else {
				$totals.empty();
				$cart.trigger( 'updated_addons' );
			}
 
		});
 
		$( this ).find( '.addon-custom, .addon-custom-textarea, .product-addon input, .product-addon textarea, .product-addon select, input.qty' ).change();
 
		// When default variation exists, 'found_variation' must be triggered
		$( this ).find( '.variations select' ).change();
	};
 
	// Quick view
	$( document.body ).on( 'quick-view-displayed', function() {
		$( this ).find( '.cart:not(.cart_group)' ).each( function() {
			$( this ).init_addon_totals();
		});
	});
 
	// Composites
	$( document.body ).find( '.component' ).on( 'wc-composite-component-loaded', function() {
		$( this ).find( '.cart' ).each( function() {
			$( this ).init_addon_totals();
		});
	});
 
	// Variations
	$(document.body).find('form.variations_form.cart').on('wc_variation_form', function () {
		$(this).init_addon_totals();
	});
 
	// Initialize
	$(document.body).find('.cart').not('.cart_group, .variations_form').each(function () {
		$(this).init_addon_totals();
	});
});
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por joel (1269 intervenciones) el 21/04/2021 15:13:13
Hola Oscar, parece que es la linea que comentas... has probado a comentarla?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 12
Ha aumentado su posición en 15 puestos en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por oscar (4 intervenciones) el 21/04/2021 16:11:06
El problema es que no sé que atributos debería cambiar ¿podrías ayudarme?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 393
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por Jefferson (203 intervenciones) el 21/04/2021 21:01:55
Hola Oscar

Me surge una duda ?

Si te haz currado un pagina tan bien hecha, como es que no sabrás que atributos cambiar en la condicional que te da el error ???

Porque a todas luces se ve claro el error en la condicional de la linea 95
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de joel
Val: 3.828
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema Checkbox - Marcar - Desmarcar

Publicado por joel (1269 intervenciones) el 22/04/2021 07:33:44
No tienes que cambiar nada, simplemente comenta o quita la linea
1
$(this).attr('disabled', true);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar