(function($) { /** * jQuery debugging helper. * * Invented for Dreditor. * * @usage * $.debug(var [, name]); * $variable.debug( [name] ); */ jQuery.extend({ debug: function () { // Setup debug storage in global window. We want to look into it. window.debug = window.debug || []; args = jQuery.makeArray(arguments); // Determine data source; this is an object for $variable.debug(). // Also determine the identifier to store data with. if (typeof this == 'object') { var name = (args.length ? args[0] : window.debug.length); var data = this; } else { var name = (args.length > 1 ? args.pop() : window.debug.length); var data = args[0]; } // Store data. window.debug[name] = data; // Dump data into Firebug console. if (typeof console != 'undefined') { console.log(name, data); } return this; } }); // @todo Is this the right way? jQuery.fn.debug = jQuery.debug; })(jQuery); ; (function ($, Drupal) { Drupal.behaviors.wid = { attach: function(context, settings) { console.log('wid'); /*$('#widget-pedido-form #edit-checob', context).once('ch').each(function(){ console.log('check'); $('#widget-pedido-form').on('submit', function(e){ e.preventDefault(); console.log('prevent'); }); $('#widget-pedido-form button.checob', context).once('checob').on('click', function(){ console.log('Click en el botón'); //Calcular }); $('#widget-pedido-form input[type="text"]', context).once('mov1').on('keyup', function(e){ console.log('keyup'); chequearCampos(); }); $('#widget-pedido-form select', context).once('mov2').on('change', function(e){ console.log('change'); chequearCampos(); }); });*/ function chequearCampos(){ var sumar = 0; var tipo = $('#widget-pedido-form select').val(); var cant = ($('#widget-pedido-form input[name="cantidad"]').val()).trim(); var cp = ($('#widget-pedido-form input[name="cp-municipio"]').val()).trim(); console.log('CP: ' + cp + '. TIPO: ' + tipo + '. Liters: ' + cant); if(tipo != ''){ sumar++; } else { console.log('Select vacío'); } if(cp != ''){ //Comprobar formato? if(cp.length == 5){ if($.isNumeric(cp)){ sumar++; $('#widget-pedido-form span.msg_cp').html(''); } else { $('#widget-pedido-form span.msg_cp').html('Sólo se permiten números en este campo') console.log('CP: no es numero'); } } else { console.log('CP: Menos de 5'); } } else { console.log('CP: vacío'); } if(cant != ''){ //Comprobar formato? if(cant.length < 3){ $('#widget-pedido-form span.msg_cantidad').html('No llega a la cantidad mínima') console.log('Litros: menos de 3'); } else { if($.isNumeric(cant)){ sumar++; $('#widget-pedido-form span.msg_cantidad').html(''); } else { $('#widget-pedido-form span.msg_cantidad').html('Sólo se permiten números en este campo') console.log('Litros: no es numero'); } } } else { console.log('Litros: vacío'); } $('#widget-pedido-form button.checob').attr('disabled', sumar < 3); console.log('Sumar es: ' + sumar); } } }; })(jQuery, Drupal);;