Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/05/2012, 19:23
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: borrar los campos de formulario que esta en una ventana modal de jquery

amigos ya logro que al darle cancelar se limpie el campo de texto me falta que se limpien los checkbox

les muestro mi codigo

Código Javascript:
Ver original
  1. select: function(start, end, allDay) {
  2.            
  3.          $("#dialog-form").dialog('open');
  4.          $( "#dialog:ui-dialog" ).dialog( "destroy" );
  5.          var title = $( "#title" ),
  6.          allFields = $( [] ).add( title ),
  7.          tips = $( ".validateTips" );
  8.                 function updateTips( t ) {
  9.             tips
  10.                 .text( t )
  11.                 .addClass( "ui-state-highlight" );
  12.             setTimeout(function() {
  13.                 tips.removeClass( "ui-state-highlight", 1500 );
  14.             }, 500 );
  15.         }
  16.  
  17.         function checkLength( o, n, min, max ) {
  18.             if ( o.val().length > max || o.val().length < min ) {
  19.                 o.addClass( "ui-state-error" );
  20.                 updateTips( "Length of " + n + " must be between " +
  21.                     min + " and " + max + "." );
  22.                 return false;
  23.             } else {
  24.                 return true;
  25.             }
  26.         }
  27.  
  28.         function checkRegexp( o, regexp, n ) {
  29.             if ( !( regexp.test( o.val() ) ) ) {
  30.                 o.addClass( "ui-state-error" );
  31.                 updateTips( n );
  32.                 return false;
  33.             } else {
  34.                 return true;
  35.             }
  36.         }
  37.        
  38.        
  39.                  
  40.         $( "#dialog-form" ).dialog({
  41.             autoOpen: false,
  42.             height: 580,
  43.             width: 850,
  44.             modal: true,
  45.             buttons: {
  46.                 "Crear Nuevo Evento": function() {
  47.                
  48.                 var bValid = true;
  49.                     allFields.removeClass( "ui-state-error" );
  50.  
  51.                     bValid = bValid && checkLength( title, "title", 3, 80 );
  52.                     bValid = bValid && checkRegexp( title, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
  53.                    
  54.                         var arrayOpt = new Array;
  55.               $('input[type=checkbox]').each(function() {
  56.                         if ($(this).attr('name') == 'opcion[]') {
  57.                             if ($(this).attr('checked') == 'checked') {
  58.                                 arrayOpt.push($(this).val());
  59.                                
  60.                             }
  61.                         }
  62.                     });
  63.                 //alert (arrayOpt);
  64.          $("#start").val($.fullCalendar.formatDate(start, 'MM/dd/yyyy HH:mm:ss'));
  65.          $("#end").val($.fullCalendar.formatDate(end, 'MM/dd/yyyy HH:mm:ss'));
  66.          $("#allDay").val(allDay);
  67.                
  68.                 var titleq = $("#title").val();
  69.                 var startq = $("#start").val();
  70.                 var endq = $("#end").val();
  71.                 var allDayq = $("#allDay").val();
  72.                 var nombre = $("#autor").val();
  73.                
  74.                  
  75.              
  76.               /*$('#modal').each (function(){
  77.               this.reset();
  78.               });*/
  79.                   if ( bValid ) {
  80.                   $.ajax({
  81.                   url:'archivo.php',
  82.                   type:'post',
  83.                   data:'opciones='+arrayOpt+'&title='+titleq+'&start='+startq+'&end='+endq+'&allDay='+allDay+'&nombre='+nombre,
  84.                   }).done(function(data) {
  85.                  //alert(titleq+" "+arrayOpt+" "+startq+" "+endq);
  86.                  $('#calendar').fullCalendar( 'refetchEvents' )
  87.                
  88.    
  89.                   });
  90.                   $( this ).dialog( "close" );
  91.                   }
  92.                     //$( this ).dialog( "close" );
  93.                                        
  94.                    
  95.                 },
  96.                
  97.                
  98.                 Cancelar: function() {
  99.                     $( this ).dialog( "close" );
  100.                    
  101.                    
  102.                 }
  103.             },
  104.             close: function() {
  105.                 allFields.val( "" ).removeClass( "ui-state-error" );
  106.             }
  107.         });
  108.  
  109.    
  110.                    
  111.                
  112.                
  113.        }