[Ror-es] cursor por defecto en un campo

William Betancur ruby-forum-incoming at andreas-s.net
Mon Sep 3 20:04:17 GMT 2007


Damian Janowski wrote:
> On 9/3/07, Fernando Seves <fernando.seves at gmail.com> wrote:
>>
>> Buenas
>>
>> Como podr�a poner el cursor por defecto en el campo login al cargar la
>> pagina? Existe alg�n helper para esto?
>>
>> <%= text_field 'user', 'login', :class => "input" %>
> 
> Considerando que est�s incluyendo Prototype, debajo de todo el formulario:
> 
> <%= javascript_tag "Element.focus('user_login')" %>
> 
> Sin Prototype:
> 
> <%= javascript_tag "if ((e = document.getElementById('user_login')) &&
> e.focus) e.focus();" %>
> 
> Pas�ndolo a un helper, por supuesto ;)
> 
> Saludos

una forma de hacerlo para todos los formularios es agregando este codigo 
en layouts/aplication.rhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>Parking</title>
  <%= stylesheet_link_tag 'scaffold' %>
  <%= javascript_include_tag :defaults %>

<script language="JavaScript">
<!-- Begin
  function setFocus() {
  if (document.forms.length > 0) {
     var field = document.forms[0];
     for (i = 0; i < field.length; i++) {
         if ((field.elements[i].type == "text") || 
(field.elements[i].type == "textarea")
            || (field.elements[i].type.toString().charAt(0) == "s")) {
            document.forms[0].elements[i].focus();
            break;
         }
     }
  }
}
// End -->
</script>

</head>

esto es js.

saludos
-- 
Posted via http://www.ruby-forum.com/.


More information about the Ror-es mailing list