Foros del Web » Programando para Internet » Jquery »

Validar y dar formato a Datebox jquery

Estas en el tema de Validar y dar formato a Datebox jquery en el foro de Jquery en Foros del Web. hola buenas tardes a todos los foristas bueno les comento soy nuevo en lo que se refiere a programacion web (html, js, php, jquery ) ...
  #1 (permalink)  
Antiguo 13/04/2015, 15:58
 
Fecha de Ingreso: abril-2015
Mensajes: 13
Antigüedad: 9 años
Puntos: 0
Validar y dar formato a Datebox jquery

hola buenas tardes a todos los foristas bueno les comento soy nuevo en lo que se refiere a programacion web (html, js, php, jquery ) estoy aprendiendo de forma autodidacta leyendo manuales viendo tutoriales y visitando este foro bueno tengo una duda y que no he podido resolver debido a mi escaso conocimiento estoy realizando un CRUD con jquery mi codigo es el siguiente

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.     <meta charset="UTF-8">
  3.     <title>Basic CRUD Application - jQuery EasyUI CRUD Demo</title>
  4.     <link rel="stylesheet" type="text/css" href="lib/themes/metro/easyui.css">
  5.     <link rel="stylesheet" type="text/css" href="lib/themes/icon.css">
  6.     <link rel="stylesheet" type="text/css" href="lib/themes/color.css">
  7.     <link rel="stylesheet" type="text/css" href="lib/demo.css">
  8.     <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
  9.     <script type="text/javascript" src="lib/jquery.easyui.min.js"></script>
  10. </head>
  11.     <h2>Basic CRUD Application</h2>
  12.     <p>Click the buttons on datagrid toolbar to do crud actions.</p>
  13.    
  14.     <table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:250px"
  15.     url="get_users.php"
  16.     toolbar="#toolbar" pagination="true"
  17.     rownumbers="true" fitColumns="true" singleSelect="true">
  18.     <thead>
  19.         <tr>
  20.             <th field="nombre" width="70">nombre</th>
  21.             <th field="lugar" width="70">lugar</th>
  22.             <th field="concepto" width="70">Concepto</th>
  23.             <th field="ident" width="70">ident</th>
  24.             <th field="servicio" width="70">servicio</th>
  25.             <th field="fecha" width="50">fecha</th>
  26.         </tr>
  27.     </thead>
  28. <div id="toolbar">
  29.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a>
  30.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a>
  31.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>
  32. </div>
  33.  
  34. <div id="dlg" class="easyui-dialog" style="width:400px;height:380px;padding:10px 20px"
  35. closed="true" buttons="#dlg-buttons">
  36. <div class="ftitle">User Information</div>
  37. <form id="fm" method="post" novalidate>
  38.     <div class="fitem">
  39.         <label>Nombre:</label>
  40.         <input name="nombre" class="easyui-textbox" required="true">
  41.     </div>
  42.     <div class="fitem">
  43.         <label>Lugar:</label>
  44.         <input name="lugar" class="easyui-textbox" required="true">
  45.     </div>
  46.     <div class="fitem">
  47.         <label>Concepto:</label>
  48.         <input name="concepto" class="easyui-textbox">
  49.     </div>
  50.     <div class="fitem">
  51.         <label>Email:</label>
  52.         <input name="ident" class="easyui-textbox" validType="date">
  53.     </div>
  54.     <div class="fitem">
  55.     <label>Servicio:</label>
  56.     <input  name="servicio" class="easyui-combobox" data-options="
  57.     valueField: 'label',
  58.     textField: 'value',
  59.     data: [{
  60.     label: 'compra',
  61.     value: 'compra'
  62.     },{
  63.     label: 'venta',
  64.     value: 'venta'
  65.     },{
  66.     label: 'renta',
  67.     value: 'renta'
  68.     }]" />
  69.      </div>
  70.      <div class="fitem">
  71.         <label>FECHA:</label>
  72.         <input name="fecha" class="easyui-datebox" validType="date">
  73.     </div>
  74.   </form>
  75. </div>
  76. <div id="dlg-buttons">
  77.     <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
  78.     <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
  79. </div>
  80. <script type="text/javascript">
  81.     var url;
  82.  
  83.     function newUser(){
  84.         $('#dlg').dialog('open').dialog('setTitle','New User');
  85.         $('#fm').form('clear');
  86.         url = 'save_user.php';
  87.     }
  88.     function editUser(){
  89.         var row = $('#dg').datagrid('getSelected');
  90.         if (row){
  91.             $('#dlg').dialog('open').dialog('setTitle','Edit User');
  92.             $('#fm').form('load',row);
  93.             url = 'update_user.php?id='+row.id;
  94.         }
  95.     }
  96.     function saveUser(){
  97.         $('#fm').form('submit',{
  98.             url: url,
  99.             onSubmit: function(){
  100.                 return $(this).form('validate');
  101.             },
  102.             success: function(result){
  103.                 var result = eval('('+result+')');
  104.                 if (result.errorMsg){
  105.                     $.messager.show({
  106.                         title: 'Error',
  107.                         msg: result.errorMsg
  108.                     });
  109.                 } else {
  110.                         $('#dlg').dialog('close');      // close the dialog
  111.                         $('#dg').datagrid('reload');    // reload the user data
  112.                     }
  113.                 }
  114.             });
  115.     }
  116.     function destroyUser(){
  117.         var row = $('#dg').datagrid('getSelected');
  118.         if (row){
  119.             $.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
  120.                 if (r){
  121.                     $.post('destroy_user.php',{id:row.id},function(result){
  122.                         if (result.success){
  123.                                 $('#dg').datagrid('reload');    // reload the user data
  124.                             } else {
  125.                                 $.messager.show({   // show error message
  126.                                     title: 'Error',
  127.                                     msg: result.errorMsg
  128.                                 });
  129.                             }
  130.                         },'json');
  131.                 }
  132.             });
  133.         }
  134.     }
  135.  
  136. <style type="text/css">
  137.     #fm{
  138.         margin:0;
  139.         padding:10px 30px;
  140.     }
  141.     .ftitle{
  142.         font-size:14px;
  143.         font-weight:bold;
  144.         padding:5px 0;
  145.         margin-bottom:10px;
  146.         border-bottom:1px solid #ccc;
  147.     }
  148.     .fitem{
  149.         margin-bottom:5px;
  150.     }
  151.     .fitem label{
  152.         display:inline-block;
  153.         width:80px;
  154.     }
  155.     .fitem input{
  156.         width:160px;
  157.     }
  158. </body>
  159. </html>

tengo un campo date en my base y ocupo un datebox para ingresar la fecha pero no he podido validarlo ni tampoco y podido hacer que cuando me carge los datos para editar me tome este formato "dd-mm-YYYY" ya que me toma este formato "mm-dd-YYYY" de antemano agradecere cualquier opinion o sugerencia de antemano muchas gracias
  #2 (permalink)  
Antiguo 13/04/2015, 19:33
 
Fecha de Ingreso: abril-2015
Mensajes: 13
Antigüedad: 9 años
Puntos: 0
Respuesta: Validar y dar formato a Datebox jquery

he intentado darle formato con este codigo
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.         function myformatter(date){
  3.             var y = date.getFullYear();
  4.             var m = date.getMonth()+1;
  5.             var d = date.getDate();
  6.             return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
  7.         }
  8.         function myparser(s){
  9.             if (!s) return new Date();
  10.             var ss = (s.split('-'));
  11.             var y = parseInt(ss[0],10);
  12.             var m = parseInt(ss[1],10);
  13.             var d = parseInt(ss[2],10);
  14.             if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
  15.                 return new Date(y,m-1,d);
  16.             } else {
  17.                 return new Date();
  18.             }
  19.         }
  20.     </script>

funciona pero a la hora de guardar simplemente no hace nada mi formulario se queda como si no se realizara ninguna accion
  #3 (permalink)  
Antiguo 14/04/2015, 06:20
(Desactivado)
 
Fecha de Ingreso: abril-2013
Ubicación: rosario
Mensajes: 248
Antigüedad: 11 años
Puntos: 17
Respuesta: Validar y dar formato a Datebox jquery

para la carga de datos, yo lo haria con php y que te muestre la fecha con el formato que vos quieras, algo asi
Código PHP:
Ver original
  1. <input  type="text" value="<?php echo date("d-m-Y", strtotime($originalDate))?>" />

Luego para validarlo, nose si estas utilizando algun plugin o lo haces a mano.
  #4 (permalink)  
Antiguo 14/04/2015, 10:03
 
Fecha de Ingreso: abril-2015
Mensajes: 13
Antigüedad: 9 años
Puntos: 0
Respuesta: Validar y dar formato a Datebox jquery

hola diurno10 gracias por tomarte la molestia de leer mi post te comento pero el detalle con lo que me comentas es que yo estoy utilizando un
Código HTML:
Ver original
  1. class="easyui-datebox"
de jquery y al utilizar datebox el formato como me lo mensionas no funciona , con este código si modifica el formato orginal que trae por defecto datebox


Código HTML:
Ver original
  1. 1.<script type="text/javascript">
  2.  
  3. 2.        function myformatter(date){
  4.  
  5. 3.            var y = date.getFullYear();
  6.  
  7. 4.            var m = date.getMonth()+1;
  8.  
  9. 5.            var d = date.getDate();
  10.  
  11. 6.            return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
  12.  
  13. 7.        }
  14.  
  15. 8.        function myparser(s){
  16.  
  17. 9.            if (!s) return new Date();
  18.  
  19. 10.            var ss = (s.split('-'));
  20.  
  21. 11.            var y = parseInt(ss[0],10);
  22.  
  23. 12.            var m = parseInt(ss[1],10);
  24.  
  25. 13.            var d = parseInt(ss[2],10);
  26.  
  27. 14.            if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
  28.  
  29. 15.                return new Date(y,m-1,d);
  30.  
  31. 16.            } else {
  32.  
  33. 17.                return new Date();
  34.  
  35. 18.            }
  36.  
  37. 19.        }
  38.  
  39. 20.    </script>



pero el detalle que a la hora de ingresar mis datos simplemente se queda pasmado mi formulario de jquery, pero agradezco mucho tu interés en mi tema gracias
  #5 (permalink)  
Antiguo 06/07/2015, 15:11
 
Fecha de Ingreso: julio-2015
Mensajes: 1
Antigüedad: 8 años, 9 meses
Puntos: 0
Respuesta: Validar y dar formato a Datebox jquery

Yo pude solucionarlo colocando este escrip
<script type="text/javascript">
//Formatear el datebox Año/Mes/Dia
$('#Fecha').datebox({
value: (new Date().toString('yyyy-MMM-dd')), /* Date.js toString function to convert date into format that is being used by datebox. */
formatter : function(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
},
parser : function(s){
if (!s) return new Date();
var ss = (s.split('-'));
var y = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var d = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
});

function myformatter(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}

function myparser(s){
if (!s) return new Date();
var ss = (s.split('-'));
var y = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var d = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
</script>

Etiquetas: formato
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:26.