Skip to content

Instantly share code, notes, and snippets.

@pvilas
Created May 17, 2014 21:02
Show Gist options
  • Save pvilas/c0c6d91b8fa47f3ac675 to your computer and use it in GitHub Desktop.
Save pvilas/c0c6d91b8fa47f3ac675 to your computer and use it in GitHub Desktop.
jade express nodejs mixin generate bootstrap forms
mixin entrada(tipo, nombre, ample, etiqueta)
case tipo
when 'checkbox'
div.form-group
div.col-sm-offset-2.col-sm-10
div.checkbox
label= etiqueta
if !bound
input(type="checkbox", name=nombre)
else
input(type="checkbox", name=nombre, value=valores[nombre])
when 'submit'
div.form-group
div.col-sm-offset-2.col-sm-10
button.btn.btn-default(type="submit")=nombre
if ample>0
span.espaciador-botons o
a(href=etiqueta) Cancelar
default
if !bound
if tipo=='text' || tipo=='email'
div.form-group
label.col-sm-2.control-label(for= nombre)= etiqueta
div(class= 'col-sm-'+ample)
input.form-control( type= tipo, id= "id-"+nombre, name= nombre)
else
if errors && (nombre in errors)
if (nombre in errors)
div.form-group.has-error
label.col-sm-2.control-label(for= nombre)= etiqueta
div(class= 'col-sm-'+ample)
input.form-control.has-error.has-feedback( type= tipo, id= "id-"+nombre, name= nombre, value= valores[nombre])
span.class= errors[nombre].msg
else
div.form-group.has-success
label.col-sm-2.control-label(for= nombre)= etiqueta
div(class= 'col-sm-'+ample)
input.form-control.has-success( type= tipo, id= "id-"+nombre, name= nombre, value= valores[nombre])
// import the mixin
include entrada
form#usuarios-nuevo.form-horizontal(role="form", action="/users/new", method="post")
+entrada( 'text', 'nickname', 3, 'Nickname')
+entrada( 'text', 'descripcion', 6, 'Descripción')
+entrada( 'email', 'email', 5, 'email')
+entrada( 'checkbox', 'es_admin', 5, 'Es admin')
+entrada( 'checkbox', 'es_superuser', 5, 'es_superuser')
+entrada( 'submit', 'Guardar', 1, '/users')
script $('input.has-error').first().focus();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment