` or ` ` has a given value.
\#\#\# Example: Select options
The controlling form field gets an `up-switch` attribute with a selector for the elements to show or hide:
Basic parts
Advanced parts
Very advanced parts
The target elements can use [`[up-show-for]`](/up-show-for) and [`[up-hide-for]`](/up-hide-for)
attributes to indicate for which values they should be shown or hidden:
only shown for advancedness = basic
hidden for advancedness = basic
shown for advancedness = advanced or very-advanced
\#\#\# Example: Text field
The controlling ` ` gets an `up-switch` attribute with a selector for the elements to show or hide:
only shown for user alice
You can also use the pseudo-values `:blank` to match an empty input value,
or `:present` to match a non-empty input value:
please enter a username
\#\#\# Example: Checkbox
For checkboxes you can match against the pseudo-values `:checked` or `:unchecked`:
only shown when checkbox is checked
only shown when checkbox is unchecked
Of course you can also match against the `value` property of the checkbox element:
only shown when checkbox is checked
@selector input[up-switch]
@param {string} up-switch
A CSS selector for elements whose visibility depends on this field's value.
@stable
###
###**
Only shows this element if an input field with [`[up-switch]`](/input-up-switch) has one of the given values.
See [`input[up-switch]`](/input-up-switch) for more documentation and examples.
@selector [up-show-for]
@param {string} [up-show-for]
A space-separated list of input values for which this element should be shown.
@stable
###
###**
Hides this element if an input field with [`[up-switch]`](/input-up-switch) has one of the given values.
See [`input[up-switch]`](/input-up-switch) for more documentation and examples.
@selector [up-hide-for]
@param {string} [up-hide-for]
A space-separated list of input values for which this element should be hidden.
@stable
###
up.compiler '[up-switch]', (switcher) ->
switchTargets(switcher)
up.on 'change', '[up-switch]', (event, switcher) ->
switchTargets(switcher)
up.compiler '[up-show-for]:not(.up-switched), [up-hide-for]:not(.up-switched)', (element) ->
switchTarget(element)
###**
Observes this field and runs a callback when a value changes.
This is useful for observing text fields while the user is typing.
If you want to submit the form after a change see [`input[up-autosubmit]`](/input-up-autosubmit).
The programmatic variant of this is the [`up.observe()`](/up.observe) function.
\#\#\# Examples
The following would run a global `showSuggestions(value)` function
whenever the ` ` changes:
\#\#\# Callback context
The script given to `up-observe` runs with the following context:
| Name | Type | Description |
| -------- | --------- | ------------------------------------- |
| `value` | `string` | The current value of the field |
| `this` | `Element` | The form field |
| `$field` | `jQuery` | The form field as a jQuery collection |
@selector input[up-observe]
@param {string} up-observe
The code to run when the field's value changes.
@param {string} up-delay
The number of miliseconds to wait after a change before the code is run.
@stable
###
###**
Observes this form and runs a callback when any field changes.
This is useful for observing text fields while the user is typing.
If you want to submit the form after a change see [`input[up-autosubmit]`](/input-up-autosubmit).
The programmatic variant of this is the [`up.observe()`](/up.observe) function.
\#\#\# Example
The would call a function `somethingChanged(value)`
when any ` ` within the `
\#\#\# Callback context
The script given to `up-observe` runs with the following context:
| Name | Type | Description |
| -------- | --------- | ------------------------------------- |
| `value` | `string` | The current value of the field |
| `this` | `Element` | The form field |
| `$field` | `jQuery` | The form field as a jQuery collection |
@selector form[up-observe]
@param {string} up-observe
The code to run when any field's value changes.
@param {string} up-delay
The number of miliseconds to wait after a change before the code is run.
@stable
###
up.compiler '[up-observe]', (formOrField) -> observe(formOrField)
###**
[Observes](/up.observe) this form field and submits the form when its value changes.
Both the form and the changed field will be assigned a CSS class [`up-active`](/form-up-active)
while the autosubmitted form is loading.
The programmatic variant of this is the [`up.autosubmit()`](/up.autosubmit) function.
\#\#\# Example
The following would automatically submit the form when the query is changed:
@selector input[up-autosubmit]
@param {string} up-delay
The number of miliseconds to wait after a change before the form is submitted.
@stable
###
###**
[Observes](/up.observe) this form and submits the form when *any* field changes.
Both the form and the field will be assigned a CSS class [`up-active`](/form-up-active)
while the autosubmitted form is loading.
The programmatic variant of this is the [`up.autosubmit()`](/up.autosubmit) function.
\#\#\# Example
This will submit the form when either query or checkbox was changed:
@selector form[up-autosubmit]
@param {string} up-delay
The number of miliseconds to wait after a change before the form is submitted.
@stable
###
up.compiler '[up-autosubmit]', (formOrField) -> autosubmit(formOrField)
up.compiler '[autofocus]', { batch: true }, (inputs) -> u.last(inputs).focus()
up.on 'up:framework:reset', reset
<% if ENV['JS_KNIFE'] %>knife: eval(Knife.point)<% end %>
config: config
submit: submit
observe: observe
validate: validate
autosubmit: autosubmit
fieldSelector: fieldSelector
fields: findFields
submissionFields: findSubmissionFields
up.submit = up.form.submit
up.observe = up.form.observe
up.autosubmit = up.form.autosubmit
up.validate = up.form.validate