Skip to content

Instantly share code, notes, and snippets.

@williammincy
Last active August 12, 2017 16:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save williammincy/ea05408f1b64067d59f90c246021c815 to your computer and use it in GitHub Desktop.
Save williammincy/ea05408f1b64067d59f90c246021c815 to your computer and use it in GitHub Desktop.
pug mixin for easy form field creation
mixin inputText(id, label, val)
div.row
label(for= id)= label
input(type="text", name= id, id= id, value= val,autocomplete="off")
mixin inputPassword(id, label, val)
div.row
label(for= id)= label
input(type="password", name= id, id= id, value= val,autocomplete="off")
mixin inputTextfield(id, label, val)
div.row
label(for= id)= label
textarea(rows="5", name= id, id= id, value= val,autocomplete="false")
mixin inputToggle(id, label, checked)
div.row
label(for= id)
input(type="checkbox", name= id, id= id, checked= checked, autocomplete="off")
span= label
mixin inputSelect(id, label, selected, vals)
div.row
label(for= label)= label
select(id= id, name= id)
each val in vals
- var isSelected = (selected==val[1]) ? true : false
option(value= val[0], selected= isSelected)= val[1]
mixin inputToggleCollection(id, label, vals, checked)
- var active = []
- if (checked!=undefined) {
- active = checked.split(",")
- }
fieldset
legend= label
each val in vals
- var isSelected = (active.indexOf(val)>-1) ? true : false
+inputToggle(val.replace(/\s/g,''), val, isSelected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment