Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.

Commit 0bb2db6

Browse files
author
Ben Titcomb
committed
Add a simple way to show/hide elements containing contextual options for an input.
1 parent 939c6e7 commit 0bb2db6

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Set an element to display for any input(e.g. select) depending on its value.
2+
# Typically, this element would contain some options, but it could be
3+
# pretty much anything.
4+
5+
class outpost.ContextOptions
6+
defaults: {}
7+
8+
constructor: (@options={}) ->
9+
_.defaults @options, @defaults
10+
11+
# Elements
12+
@form = $ @options.form
13+
@containers = $.map @options.containers, (c) -> {value: c.value, container: $(c.container)}
14+
@valueField = $ @options.valueField, @form
15+
16+
@valueField.on
17+
change: (event) =>
18+
@getValue()
19+
@toggleVisibility()
20+
21+
@originalStatus = @getValue()
22+
@toggleVisibility()
23+
24+
toggleVisibility: ->
25+
val = @getValue()
26+
_.each @containers, (c) =>
27+
if val is c.value
28+
c.container.show()
29+
else
30+
c.container.hide()
31+
32+
getValue: ->
33+
@status = $("option:selected", @valueField).val()

0 commit comments

Comments
 (0)