Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Problema al obtener valor de un grupo de botones

Estas en el tema de Problema al obtener valor de un grupo de botones en el foro de Frameworks JS en Foros del Web. Saludos a todos! Me estoy basando en un ejemplo de jquery ui(dialog modal-form para ser precisos) Código: http://jqueryui.com/demos/dialog/modal-form.html con la diferencia que estoy usando datepicker ...
  #1 (permalink)  
Antiguo 17/02/2010, 12:42
 
Fecha de Ingreso: octubre-2008
Mensajes: 109
Antigüedad: 15 años, 5 meses
Puntos: 0
Problema al obtener valor de un grupo de botones

Saludos a todos!
Me estoy basando en un ejemplo de jquery ui(dialog modal-form para ser precisos)
Código:
http://jqueryui.com/demos/dialog/modal-form.html
con la diferencia que estoy usando datepicker y un grupo de botones de radio.

El problema es que al agregar un tercer elemento solo me muestra el valor de fecha y no el valor del radio seleccionado. Usando firebug veo que en el tercer intento pasa el elemento pero sin valores, es decir para la primera vez obtengo esto
Código:
[input#motivo1 1,input#motivo2 2,input#motivo3 3]
que a mi parecer le pasa los valores aunque ninguno este seleccionado.Eso es el nombre y valor de los botones de radio, pero la segunda vez que lo hago solo obtengo el nombre sin sus valores.
Como puedo pasar el valor que he seleccionado??

Aquí mi código:
Código HTML:
<div class="demo">

<div id="dialog" title="Create new user">
	<p id="validateTips">Seleccione cada una de las opciones.</p>

	<form>
	<fieldset>
	    <label for="fecha"><strong>Fecha</strong></label>
		<input type="text" name="datepicker" id="datepicker" class="text ui-widget-content ui-corner-all" />
		<label for="Motivo"><strong>Motivo</strong></label><br /><div id="areaMotivo">
        <input type="radio" name="motivo" id="motivo1" style="float:left" value="1" />Vacaci&oacute;n
        <br /><br /><input type="radio" name="motivo" id="motivo2" style="float:left" value="2">D&iacute;a feriado
        <br  /><br  /><input type="radio" name="motivo" id="motivo3" style="float:left"  value="3"/>Contingencia<br />
        </div>
	</fieldset>
	</form>
</div>


<div id="users-contain" class="ui-widget">

		<h1>Existing Users:</h1>


	<table id="users" class="ui-widget ui-widget-content">
		<thead>
			<tr class="ui-widget-header ">
				<th>Fecha</th>
                <th>Motivo</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>12-10-2010</td>
				<td>[email protected]</td>
			</tr>
		</tbody>
	</table>
</div>
<button id="create-user" class="ui-button ui-state-default ui-corner-all">Agregar d&iacute;a</button>

</div><!-- End demo -->

<div class="demo-description">

<p>Use a modal dialog to require that the user enter data during a multi-step process.  Embed form markup in the content area, set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p>

</div><!-- End demo-description --> 

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.  
  3.     $(function() {
  4.         var zz = $("input[type='radio']:checked").val();
  5.         var fecha = $("#datepicker"),
  6.             motivo = $("input[type='radio']"), //aqui es donde la primera vez tengo los valores, pero a la siguiente no trae valores
  7.             allFields = $([]).add(fecha).add(motivo),
  8.             tips = $("#validateTips");
  9.  
  10.         function updateTips(t) {
  11.             tips.text(t).effect("highlight",{},1500);
  12.         }
  13.  
  14.         function checkLength(o,n,min,max) {
  15.  
  16.             if ( o.val().length > max || o.val().length < min ) {
  17.                 o.addClass('ui-state-error');
  18.                 updateTips("Debe seleccionar una fecha.");
  19.                 return false;
  20.             } else {
  21.                 return true;
  22.             }
  23.  
  24.         }
  25.        
  26.         function opcionSel(o,n, valor) {
  27.         var xxx = valor;
  28.             var sel = $('#motivo').val();
  29.              valor = sel.val();
  30.             if( $("input[type='radio']:checked").length == 0){
  31.            
  32.             $("#areaMotivo").addClass('ui-state-error');
  33.                 updateTips("Debe seleccionar un motivo.");
  34.             return false;
  35.             }
  36.             else{
  37.             return true;
  38.             }
  39.            
  40.            
  41.            
  42. }
  43.            
  44. function checkRegexp(o,regexp,n) {
  45.  
  46.             if ( !( regexp.test( o.val() ) ) ) {
  47.                 o.addClass('ui-state-error');
  48.                 updateTips(n);
  49.                 return false;
  50.             } else {
  51.                 return true;
  52.             }
  53.  
  54.         }
  55.        
  56.         $("#dialog").dialog({
  57.             bgiframe: true,
  58.             autoOpen: false,
  59.             height: 300,
  60.             modal: true,
  61.             buttons: {
  62.                 'Agregar día': function() {
  63.                     var bValid = true;
  64.                     allFields.removeClass('ui-state-error');
  65.  
  66.                     bValid = bValid && checkLength(fecha,"fecha",10,10);
  67.                     bValid = bValid && opcionSel(motivo,"motivo", motivo.val());
  68.                    
  69.                     //bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
  70.                    
  71.                     if (bValid) {
  72.                         $('#users tbody').append('<tr>' +
  73.                             '<td>' + fecha.val() + '</td>' +
  74.                             '<td>' + $("input[type='radio']:checked").val() + '</td>' +
  75.                             '</tr>');
  76.                         $(this).dialog('close');
  77.                     }
  78.                 },
  79.                 Cancelar: function() {
  80.                     $(this).dialog('close');
  81.                 }
  82.             },
  83.             close: function() {
  84.                 allFields.val('').removeClass('ui-state-error');
  85.             }
  86.         });
  87.        
  88.        
  89.        
  90.         $('#create-user').click(function() {
  91.             $('#dialog').dialog('open');
  92.         })
  93.         .hover(
  94.             function(){
  95.                 $(this).addClass("ui-state-hover");
  96.             },
  97.             function(){
  98.                 $(this).removeClass("ui-state-hover");
  99.             }
  100.         ).mousedown(function(){
  101.             $(this).addClass("ui-state-active");
  102.         })
  103.         .mouseup(function(){
  104.                 $(this).removeClass("ui-state-active");
  105.         });
  106.  
  107.  
  108.    
  109.     $(function() {
  110.         $("#datepicker").datepicker({ dateFormat: 'yy-mm-dd'});
  111.     });
  112.    
  113.     });
  114.     </script>

Alguien sabe que esta ocurriendo??
Ayuda por favor......

Etiquetas: botones, jquery
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 09:57.