Foros del Web » Programando para Internet » Jquery »

validar select en jquery Dialog

Estas en el tema de validar select en jquery Dialog en el foro de Jquery en Foros del Web. hola amigos me encuentro adaptando el codigo de jquery Dialog http://jqueryui.com/demos/dialog/#modal-form pero a esta ventana le adicione un select el cual necesito validar este es ...
  #1 (permalink)  
Antiguo 21/09/2012, 20:36
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
validar select en jquery Dialog

hola amigos me encuentro adaptando el codigo de jquery Dialog http://jqueryui.com/demos/dialog/#modal-form

pero a esta ventana le adicione un select el cual necesito validar


este es el codigo que estoy utilizando
Código HTML:
Ver original
  1. <select name="categoria" id="categoria">
  2.       <option value="0">Seleccione...</option>
  3.  
  4. [HIGHLIGHT="PHP"]
  5.  
  6.  <?php
  7.                         foreach($fc as $field)
  8.                         {
  9.                             echo "<option value='$field[id_categoria]'>$field[nombre_cat]</option>";
  10.                         }
  11.                     ?>
[/HIGHLIGHT]


esta ventana la utilizo para hacer insercciones


Código Javascript:
Ver original
  1. $(function() {
  2.        
  3.         $( "#dialog:ui-dialog" ).dialog( "destroy" );
  4.        
  5.             var name = $( "#name" ),
  6.             email = $( "#email" ),
  7.             telefono1 = $( "#telefono1" ),
  8.             telefono2 = $( "#telefono2" ),
  9.             fax = $( "#fax" ),
  10.             web = $( "#web" ),
  11.             comentario= $( "#comentario" ),
  12.             allFields = $( [] ).add( name ).add( email ).add( telefono1 ).add( telefono2 ).add( fax ).add( web ).add( comentario ),
  13.             tips = $( ".validateTips" );
  14.  
  15.         function updateTips( t ) {
  16.             tips
  17.                 .text( t )
  18.                 .addClass( "ui-state-highlight" );
  19.             setTimeout(function() {
  20.                 tips.removeClass( "ui-state-highlight", 1500 );
  21.             }, 500 );
  22.         }
  23.  
  24.         function checkLength( o, n, min, max ) {
  25.             if ( o.val().length > max || o.val().length < min ) {
  26.                 o.addClass( "ui-state-error" );
  27.                 updateTips( "Length of " + n + " must be between " +
  28.                     min + " and " + max + "." );
  29.                 return false;
  30.             } else {
  31.                 return true;
  32.             }
  33.         }
  34.  
  35.         function checkRegexp( o, regexp, n ) {
  36.             if ( !( regexp.test( o.val() ) ) ) {
  37.                 o.addClass( "ui-state-error" );
  38.                 updateTips( n );
  39.                 return false;
  40.             } else {
  41.                 return true;
  42.             }
  43.         }
  44.        
  45.         $( "#dialog-form" ).dialog({
  46.             autoOpen: false,
  47.             height: 600,
  48.             width: 800,
  49.             modal: true,
  50.             buttons: {
  51.                 "Crear un Destinatario": function() {
  52.                     var bValid = true;
  53.                     allFields.removeClass( "ui-state-error" );
  54.  
  55.                     bValid = bValid && checkLength( name, "username", 3, 40 );
  56.                     bValid = bValid && checkLength( email, "email", 6, 80 );
  57.                    
  58.  
  59.                     //bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
  60.                     // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
  61.                     bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. [email protected]" );
  62.                     //bValid = bValid && checkLength( password, "password", 5, 16 );
  63.                     //bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
  64.                
  65.  
  66.                    
  67.                    
  68.                 var namec = $("#name").val();
  69.                 var emailc = $("#email").val();
  70.                 var telefono1c = $("#telefono1").val();
  71.                 var telefono2c = $("#telefono2").val();
  72.                 var faxc = $("#fax").val();
  73.                 var webc = $("#web").val();
  74.                 var categoriac = $("#categoria").val();
  75.                 var comentarioc = $("#comentario").val();    
  76.                  
  77.                     if ( bValid ) {
  78.                         /*$( "#users tbody" ).append( "<tr>" +
  79.                             "<td>" + name.val() + "</td>" +
  80.                             "<td>" + email.val() + "</td>" +
  81.                             "<td>" + password.val() + "</td>" +
  82.                         "</tr>" );*/
  83.                        
  84.            
  85.             var dataString = $('#form_account').serialize();
  86.              alert('Datos serializados: '+dataString);
  87.            
  88.            
  89.                 $.ajax({
  90.               url:'archivo.php',
  91.                   type:'POST',
  92. //data:{"name":namec,"email":emailc,"telefono1":telefono1c,"telefono2":telefono2c,"fax":faxc,"web":webc,"categoria":categoriac,"comentario":comentarioc}
  93. data: dataString,
  94.  
  95.                   }).done(function() {
  96.                    cargar_usuarios();
  97.  
  98.         $(".ui-selectmenu-status").html("Seleccione...");
  99.         $('input:checkbox').removeAttr('checked');
  100.         $(".q").attr('value', 0);
  101.                  })
  102.  
  103.  
  104.        
  105.                         $( this ).dialog( "close" );
  106.                        
  107.                    
  108.                     }
  109.                 },
  110.                 Cancelar: function() {
  111.                     $('input:checkbox').removeAttr('checked');
  112.                     $(".q").attr('value', 0);
  113.                     $( this ).dialog( "close" );
  114.                    
  115.                 }
  116.             },
  117.             close: function() {
  118.                 allFields.val( "" ).removeClass( "ui-state-error" );
  119.                 $(".ui-selectmenu-status").html("Seleccione...");
  120.                 $('input:checkbox').removeAttr('checked');
  121.                 $(".q").attr('value', 0);
  122.                
  123.             }
  124.         });
  125.  
  126.         $( "#create-user" )
  127.             .button()
  128.             .click(function() {
  129.                 $( "#dialog-form" ).dialog( "open" );
  130.             });
  131.     });
  #2 (permalink)  
Antiguo 21/09/2012, 23:06
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: validar select en jquery Dialog

amigo logro validar y mostrar un error pero no de la mejor manera


Código Javascript:
Ver original
  1. bValid = bValid && checkLength( categoria, "categoria", 1, 10);

este es el codigo que se utiliza para hacer la validacion

Código Javascript:
Ver original
  1. function updateTips( t ) {
  2.             tips
  3.                 .text( t )
  4.                 .addClass( "ui-state-highlight" );
  5.             setTimeout(function() {
  6.                 tips.removeClass( "ui-state-highlight", 1500 );
  7.             }, 500 );
  8.         }
  9.  
  10.         function checkLength( o, n, min, max ) {
  11.             if ( o.val().length > max || o.val().length < min ) {
  12.                 o.addClass( "ui-state-error" );
  13.                 updateTips( "Length of " + n + " must be between " +
  14.                     min + " and " + max + "." );
  15.                
  16.                 //updateTips( "Este Campo es Requerido" );
  17.                 return false;
  18.             } else {
  19.                 return true;
  20.             }
  21.         }
  22.  
  23.         function checkRegexp( o, regexp, n ) {
  24.             if ( !( regexp.test( o.val() ) ) ) {
  25.                 o.addClass( "ui-state-error" );
  26.                 updateTips( n );
  27.                 return false;
  28.             } else {
  29.                 return true;
  30.             }
  31.         }

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:11.