unpoly-rails 0.37.0 → 0.50.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of unpoly-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +127 -25
- data/LICENSE +1 -1
- data/README_RAILS.md +4 -2
- data/Rakefile +6 -1
- data/dist/unpoly.js +3192 -2198
- data/dist/unpoly.min.js +4 -3
- data/lib/assets/javascripts/unpoly/browser.coffee +51 -63
- data/lib/assets/javascripts/unpoly/bus.coffee +58 -33
- data/lib/assets/javascripts/unpoly/classes/cache.coffee +117 -0
- data/lib/assets/javascripts/unpoly/{dom → classes}/extract_cascade.coffee +3 -3
- data/lib/assets/javascripts/unpoly/{dom → classes}/extract_plan.coffee +1 -1
- data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +57 -0
- data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +52 -0
- data/lib/assets/javascripts/unpoly/classes/motion_tracker.coffee +95 -0
- data/lib/assets/javascripts/unpoly/classes/record.coffee +16 -0
- data/lib/assets/javascripts/unpoly/classes/request.coffee +228 -0
- data/lib/assets/javascripts/unpoly/classes/response.coffee +138 -0
- data/lib/assets/javascripts/unpoly/dom.coffee +151 -142
- data/lib/assets/javascripts/unpoly/feedback.coffee +67 -38
- data/lib/assets/javascripts/unpoly/form.coffee +156 -139
- data/lib/assets/javascripts/unpoly/history.coffee +22 -19
- data/lib/assets/javascripts/unpoly/layout.coffee +108 -90
- data/lib/assets/javascripts/unpoly/link.coffee +159 -158
- data/lib/assets/javascripts/unpoly/log.coffee +5 -5
- data/lib/assets/javascripts/unpoly/modal.coffee +93 -81
- data/lib/assets/javascripts/unpoly/motion.coffee +291 -250
- data/lib/assets/javascripts/unpoly/popup.coffee +67 -53
- data/lib/assets/javascripts/unpoly/protocol.coffee +67 -16
- data/lib/assets/javascripts/unpoly/proxy.coffee +282 -211
- data/lib/assets/javascripts/unpoly/rails.coffee +3 -14
- data/lib/assets/javascripts/unpoly/syntax.coffee +54 -49
- data/lib/assets/javascripts/unpoly/tooltip.coffee +18 -25
- data/lib/assets/javascripts/unpoly/util.coffee +236 -477
- data/lib/assets/javascripts/unpoly.coffee +1 -1
- data/lib/unpoly/rails/inspector.rb +67 -22
- data/lib/unpoly/rails/version.rb +1 -1
- data/package.json +1 -1
- data/spec_app/Gemfile.lock +13 -13
- data/spec_app/app/assets/javascripts/integration_test.coffee +1 -0
- data/spec_app/app/assets/javascripts/jasmine_specs.coffee +1 -1
- data/spec_app/app/assets/stylesheets/jasmine_specs.sass +10 -0
- data/spec_app/app/controllers/binding_test_controller.rb +19 -2
- data/spec_app/app/controllers/method_test_controller.rb +16 -0
- data/spec_app/app/views/layouts/jasmine_rails/spec_runner.html.erb +20 -0
- data/spec_app/app/views/method_test/form_target.erb +17 -0
- data/spec_app/app/views/method_test/page1.erb +11 -0
- data/spec_app/app/views/method_test/page2.erb +6 -0
- data/spec_app/app/views/pages/start.erb +33 -19
- data/spec_app/config/initializers/assets.rb +5 -0
- data/spec_app/config/routes.rb +3 -0
- data/spec_app/spec/controllers/binding_test_controller_spec.rb +82 -27
- data/spec_app/spec/javascripts/helpers/agent_detector.coffee +17 -0
- data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +102 -0
- data/spec_app/spec/javascripts/helpers/last_request.js.coffee +1 -1
- data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +5 -2
- data/spec_app/spec/javascripts/helpers/promise_state.js +18 -0
- data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +9 -0
- data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +22 -0
- data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +11 -3
- data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +10 -0
- data/spec_app/spec/javascripts/helpers/to_be_error.coffee +5 -0
- data/spec_app/spec/javascripts/helpers/to_match_url.coffee +13 -0
- data/spec_app/spec/javascripts/helpers/trigger.js.coffee +13 -6
- data/spec_app/spec/javascripts/up/browser_spec.js.coffee +92 -33
- data/spec_app/spec/javascripts/up/bus_spec.js.coffee +64 -15
- data/spec_app/spec/javascripts/up/classes/.keep +0 -0
- data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +1 -0
- data/spec_app/spec/javascripts/up/dom_spec.js.coffee +759 -551
- data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +155 -82
- data/spec_app/spec/javascripts/up/form_spec.js.coffee +490 -349
- data/spec_app/spec/javascripts/up/history_spec.js.coffee +226 -179
- data/spec_app/spec/javascripts/up/layout_spec.js.coffee +253 -185
- data/spec_app/spec/javascripts/up/link_spec.js.coffee +416 -270
- data/spec_app/spec/javascripts/up/modal_spec.js.coffee +459 -330
- data/spec_app/spec/javascripts/up/motion_spec.js.coffee +198 -153
- data/spec_app/spec/javascripts/up/namespace_spec.js.coffee +9 -0
- data/spec_app/spec/javascripts/up/popup_spec.js.coffee +240 -175
- data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +38 -0
- data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +777 -303
- data/spec_app/spec/javascripts/up/rails_spec.js.coffee +24 -8
- data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +40 -23
- data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +80 -66
- data/spec_app/spec/javascripts/up/util_spec.js.coffee +227 -201
- data/spec_app/vendor/asset-libs/es6-promise-4.1.6/es6-promise.auto.js +1159 -0
- metadata +30 -7
- data/spec_app/spec/javascripts/helpers/reset_path.js.coffee +0 -7
- data/spec_app/spec/javascripts/helpers/to_equal_url.coffee +0 -11
@@ -2,7 +2,7 @@
|
|
2
2
|
Forms
|
3
3
|
=====
|
4
4
|
|
5
|
-
Unpoly comes with functionality to [submit](/form-up-target) and [validate](/up-validate)
|
5
|
+
Unpoly comes with functionality to [submit](/form-up-target) and [validate](/input-up-validate)
|
6
6
|
forms without leaving the current page. This means you can replace page fragments,
|
7
7
|
open dialogs with sub-forms, etc. all without losing form state.
|
8
8
|
|
@@ -16,7 +16,7 @@ up.form = (($) ->
|
|
16
16
|
Sets default options for form submission and validation.
|
17
17
|
|
18
18
|
@property up.form.config
|
19
|
-
@param {
|
19
|
+
@param {number} [config.observeDelay=0]
|
20
20
|
The number of miliseconds to wait before [`up.observe()`](/up.observe) runs the callback
|
21
21
|
after the input value changes. Use this to limit how often the callback
|
22
22
|
will be invoked for a fast typist.
|
@@ -28,7 +28,7 @@ up.form = (($) ->
|
|
28
28
|
By default this looks for a `<fieldset>`, `<label>` or `<form>`
|
29
29
|
around the validating input field, or any element with an
|
30
30
|
`up-fieldset` attribute.
|
31
|
-
@param {
|
31
|
+
@param {string} [config.fields=[':input']]
|
32
32
|
An array of CSS selectors that represent form fields, such as `input` or `select`.
|
33
33
|
@stable
|
34
34
|
###
|
@@ -54,51 +54,51 @@ up.form = (($) ->
|
|
54
54
|
information on how AJAX form submissions work in Unpoly.
|
55
55
|
|
56
56
|
@function up.submit
|
57
|
-
@param {Element|jQuery|
|
57
|
+
@param {Element|jQuery|string} formOrSelector
|
58
58
|
A reference or selector for the form to submit.
|
59
59
|
If the argument points to an element that is not a form,
|
60
60
|
Unpoly will search its ancestors for the closest form.
|
61
|
-
@param {
|
61
|
+
@param {string} [options.url]
|
62
62
|
The URL where to submit the form.
|
63
63
|
Defaults to the form's `action` attribute, or to the current URL of the browser window.
|
64
|
-
@param {
|
64
|
+
@param {string} [options.method='post']
|
65
65
|
The HTTP method used for the form submission.
|
66
66
|
Defaults to the form's `up-method`, `data-method` or `method` attribute, or to `'post'`
|
67
67
|
if none of these attributes are given.
|
68
|
-
@param {
|
68
|
+
@param {string} [options.target]
|
69
69
|
The selector to update when the form submission succeeds (server responds with status 200).
|
70
70
|
Defaults to the form's `up-target` attribute.
|
71
|
-
@param {
|
71
|
+
@param {string} [options.failTarget]
|
72
72
|
The selector to update when the form submission fails (server responds with non-200 status).
|
73
73
|
Defaults to the form's `up-fail-target` attribute, or to an auto-generated
|
74
74
|
selector that matches the form itself.
|
75
|
-
@param {
|
75
|
+
@param {string} [options.fallback]
|
76
76
|
The selector to update when the original target was not found in the page.
|
77
77
|
Defaults to the form's `up-fallback` attribute.
|
78
|
-
@param {
|
78
|
+
@param {boolean|string} [options.history=true]
|
79
79
|
Successful form submissions will add a history entry and change the browser's
|
80
80
|
location bar if the form either uses the `GET` method or the response redirected
|
81
81
|
to another page (this requires the `unpoly-rails` gem).
|
82
82
|
If you want to prevent history changes in any case, set this to `false`.
|
83
|
-
If you pass a
|
84
|
-
@param {
|
83
|
+
If you pass a string, it is used as the URL for the browser history.
|
84
|
+
@param {string} [options.transition='none']
|
85
85
|
The transition to use when a successful form submission updates the `options.target` selector.
|
86
86
|
Defaults to the form's `up-transition` attribute, or to `'none'`.
|
87
|
-
@param {
|
87
|
+
@param {string} [options.failTransition='none']
|
88
88
|
The transition to use when a failed form submission updates the `options.failTarget` selector.
|
89
89
|
Defaults to the form's `up-fail-transition` attribute, or to `options.transition`, or to `'none'`.
|
90
|
-
@param {
|
90
|
+
@param {number} [options.duration]
|
91
91
|
The duration of the transition. See [`up.morph()`](/up.morph).
|
92
|
-
@param {
|
92
|
+
@param {number} [options.delay]
|
93
93
|
The delay before the transition starts. See [`up.morph()`](/up.morph).
|
94
|
-
@param {
|
94
|
+
@param {string} [options.easing]
|
95
95
|
The timing function that controls the transition's acceleration. [`up.morph()`](/up.morph).
|
96
|
-
@param {Element|jQuery|
|
96
|
+
@param {Element|jQuery|string} [options.reveal=true]
|
97
97
|
Whether to reveal the target element within its viewport.
|
98
|
-
@param {
|
98
|
+
@param {boolean} [options.restoreScroll]
|
99
99
|
If set to `true`, this will attempt to [`restore scroll positions`](/up.restoreScroll)
|
100
100
|
previously seen on the destination URL.
|
101
|
-
@param {
|
101
|
+
@param {boolean} [options.cache]
|
102
102
|
Whether to force the use of a cached response (`true`)
|
103
103
|
or never use the cache (`false`)
|
104
104
|
or make an educated guess (`undefined`).
|
@@ -108,19 +108,18 @@ up.form = (($) ->
|
|
108
108
|
@param {Object} [options.headers={}]
|
109
109
|
An object of additional header key/value pairs to send along
|
110
110
|
with the request.
|
111
|
-
@param {
|
111
|
+
@param {string} [options.layer='auto']
|
112
112
|
The name of the layer that ought to be updated. Valid values are
|
113
113
|
`auto`, `page`, `modal` and `popup`.
|
114
114
|
|
115
115
|
If set to `auto` (default), Unpoly will try to find a match in the form's layer.
|
116
|
-
@param {
|
116
|
+
@param {string} [options.failLayer='auto']
|
117
117
|
The name of the layer that ought to be updated if the server sends a non-200 status code.
|
118
118
|
@return {Promise}
|
119
119
|
A promise for the successful form submission.
|
120
120
|
@stable
|
121
121
|
###
|
122
122
|
submit = (formOrSelector, options) ->
|
123
|
-
|
124
123
|
$form = $(formOrSelector).closest('form')
|
125
124
|
|
126
125
|
options = u.options(options)
|
@@ -152,11 +151,12 @@ up.form = (($) ->
|
|
152
151
|
|
153
152
|
# If we can't update the location URL, fall back to a vanilla form submission.
|
154
153
|
unless up.browser.canPushState() || options.history == false
|
154
|
+
# Don't use up.browser.navigate(); It cannot deal with file inputs.
|
155
155
|
$form.get(0).submit()
|
156
156
|
return u.unresolvablePromise()
|
157
157
|
|
158
158
|
promise = up.replace(target, url, options)
|
159
|
-
|
159
|
+
u.always promise, -> up.feedback.stop($form)
|
160
160
|
promise
|
161
161
|
|
162
162
|
###*
|
@@ -212,16 +212,16 @@ up.form = (($) ->
|
|
212
212
|
});
|
213
213
|
|
214
214
|
@function up.observe
|
215
|
-
@param {Element|jQuery|
|
215
|
+
@param {Element|jQuery|string} selectorOrElement
|
216
216
|
The form fields that wiill be observed.
|
217
217
|
|
218
218
|
You can pass one or more fields, a `<form>` or any container that contains form fields.
|
219
219
|
The callback will be run if any of the given fields change.
|
220
|
-
@param {
|
220
|
+
@param {number} [options.delay=up.form.config.observeDelay]
|
221
221
|
The number of miliseconds to wait before executing the callback
|
222
222
|
after the input value changes. Use this to limit how often the callback
|
223
223
|
will be invoked for a fast typist.
|
224
|
-
@param {Function(value, $field)|
|
224
|
+
@param {Function(value, $field)|string} onChange
|
225
225
|
The callback to run when the field's value changes.
|
226
226
|
If given as a function, it must take two arguments (`value`, `$field`).
|
227
227
|
If given as a string, it will be evaled as JavaScript code in a context where
|
@@ -251,7 +251,7 @@ up.form = (($) ->
|
|
251
251
|
delay = u.option(u.presentAttr($element, 'up-delay'), options.delay, config.observeDelay)
|
252
252
|
delay = parseInt(delay)
|
253
253
|
|
254
|
-
$fields = u.multiSelector(config.fields).
|
254
|
+
$fields = u.multiSelector(config.fields).selectInSubtree($element)
|
255
255
|
|
256
256
|
destructors = u.map $fields, (field) ->
|
257
257
|
observeField($(field), delay, callback)
|
@@ -259,49 +259,20 @@ up.form = (($) ->
|
|
259
259
|
u.sequence(destructors...)
|
260
260
|
|
261
261
|
observeField = ($field, delay, callback) ->
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
runCallback = (value) ->
|
267
|
-
processedValue = value
|
268
|
-
callbackReturnValue = callback.apply($field.get(0), [value, $field])
|
269
|
-
if u.isPromise(callbackReturnValue)
|
270
|
-
lastCallbackDone = callbackReturnValue
|
271
|
-
else
|
272
|
-
lastCallbackDone = callbackReturnValue
|
273
|
-
|
274
|
-
check = ->
|
275
|
-
value = u.submittedValue($field)
|
276
|
-
# don't run the callback for the check during initialization
|
277
|
-
if processedValue != value
|
278
|
-
nextCallback = -> runCallback(value)
|
279
|
-
timer?.cancel()
|
280
|
-
timer = u.promiseTimer(delay)
|
281
|
-
# We wait until both the delay has passed and a previous callback is done executing
|
282
|
-
$.when(timer, lastCallbackDone).then(nextCallback)
|
283
|
-
|
284
|
-
# Although (depending on the browser) we only need/receive either input or change,
|
285
|
-
# we always bind to both events in case another script manually triggers it.
|
286
|
-
changeEvents = 'input change'
|
287
|
-
|
288
|
-
$field.on(changeEvents, check)
|
289
|
-
|
290
|
-
# return destructor
|
291
|
-
return ->
|
292
|
-
$field.off(changeEvents, check)
|
293
|
-
timer?.cancel()
|
262
|
+
observer = new up.FieldObserver($field, { delay, callback })
|
263
|
+
observer.start()
|
264
|
+
return observer.stop
|
294
265
|
|
295
266
|
###*
|
296
267
|
[Observes](/up.observe) a field or form and submits the form when a value changes.
|
297
268
|
|
298
|
-
|
269
|
+
Both the form and the changed field will be assigned a CSS class [`form-up-active`](/form-up-active)
|
299
270
|
while the autosubmitted form is processing.
|
300
271
|
|
301
|
-
The unobtrusive variant of this is the [`up-autosubmit`](/up-autosubmit) attribute.
|
272
|
+
The unobtrusive variant of this is the [`up-autosubmit`](/form-up-autosubmit) attribute.
|
302
273
|
|
303
274
|
@function up.autosubmit
|
304
|
-
@param {
|
275
|
+
@param {string|Element|jQuery} selectorOrElement
|
305
276
|
The field or form to observe.
|
306
277
|
@param {Object} [options]
|
307
278
|
See options for [`up.observe()`](/up.observe)
|
@@ -329,15 +300,14 @@ up.form = (($) ->
|
|
329
300
|
target
|
330
301
|
|
331
302
|
###*
|
332
|
-
Performs a server-side validation of a form
|
333
|
-
with validation messages.
|
303
|
+
Performs a server-side validation of a form field.
|
334
304
|
|
335
305
|
`up.validate()` submits the given field's form with an additional `X-Up-Validate`
|
336
306
|
HTTP header. Upon seeing this header, the server is expected to validate (but not save)
|
337
307
|
the form submission and render a new copy of the form with validation errors.
|
338
308
|
|
339
|
-
The unobtrusive variant of this is the [`[up-validate]`](/up-validate) selector.
|
340
|
-
See the documentation for [`[up-validate]`](/up-validate) for more information
|
309
|
+
The unobtrusive variant of this is the [`input[up-validate]`](/input-up-validate) selector.
|
310
|
+
See the documentation for [`input[up-validate]`](/input-up-validate) for more information
|
341
311
|
on how server-side validation works in Unpoly.
|
342
312
|
|
343
313
|
\#\#\# Example
|
@@ -345,11 +315,11 @@ up.form = (($) ->
|
|
345
315
|
up.validate('input[name=email]', { target: '.email-errors' })
|
346
316
|
|
347
317
|
@function up.validate
|
348
|
-
@param {
|
318
|
+
@param {string|Element|jQuery} fieldOrSelector
|
349
319
|
|
350
|
-
@param {
|
320
|
+
@param {string|Element|jQuery} [options.target]
|
351
321
|
@return {Promise}
|
352
|
-
A promise that is
|
322
|
+
A promise that is fulfilled when the server-side
|
353
323
|
validation is received and the form was updated.
|
354
324
|
@stable
|
355
325
|
###
|
@@ -399,15 +369,15 @@ up.form = (($) ->
|
|
399
369
|
###*
|
400
370
|
Shows or hides a target selector depending on the value.
|
401
371
|
|
402
|
-
See [`[up-switch]`](/up-switch) for more documentation and examples.
|
372
|
+
See [`input[up-switch]`](/input-up-switch) for more documentation and examples.
|
403
373
|
|
404
374
|
This function does not currently have a very useful API outside
|
405
375
|
of our use for `up-switch`'s UJS behavior, that's why it's currently
|
406
376
|
still marked `@internal`.
|
407
377
|
|
408
378
|
@function up.form.switchTargets
|
409
|
-
@param {
|
410
|
-
@param {
|
379
|
+
@param {string|Element|jQuery} fieldOrSelector
|
380
|
+
@param {string} [options.target]
|
411
381
|
The target selectors to switch.
|
412
382
|
Defaults to an `up-switch` attribute on the given field.
|
413
383
|
@internal
|
@@ -474,7 +444,7 @@ up.form = (($) ->
|
|
474
444
|
it will usually re-render an updated copy of the form with
|
475
445
|
validation messages.
|
476
446
|
|
477
|
-
For Unpoly to be able to detect a failed form submission
|
447
|
+
For Unpoly to be able to detect a failed form submission,
|
478
448
|
the form must be re-rendered with a non-200 HTTP status code.
|
479
449
|
We recommend to use either 400 (bad request) or
|
480
450
|
422 (unprocessable entity).
|
@@ -497,8 +467,8 @@ up.form = (($) ->
|
|
497
467
|
|
498
468
|
end
|
499
469
|
|
500
|
-
Note that you can also use
|
501
|
-
[`up-validate`](/up-validate)
|
470
|
+
Note that you can also use
|
471
|
+
[`input[up-validate]`](/input-up-validate) to perform server-side
|
502
472
|
validations while the user is completing fields.
|
503
473
|
|
504
474
|
\#\#\# Redirects
|
@@ -514,7 +484,7 @@ up.form = (($) ->
|
|
514
484
|
|
515
485
|
\#\#\# Giving feedback while the form is processing
|
516
486
|
|
517
|
-
The `<form>` element will be assigned a CSS class `up-active` while
|
487
|
+
The `<form>` element will be assigned a CSS class [`up-active`](/form.up-active) while
|
518
488
|
the submission is loading.
|
519
489
|
|
520
490
|
You can also [implement a spinner](/up.proxy/#spinners)
|
@@ -522,17 +492,17 @@ up.form = (($) ->
|
|
522
492
|
and [`up:proxy:recover`](/up:proxy:recover) events.
|
523
493
|
|
524
494
|
@selector form[up-target]
|
525
|
-
@param {
|
495
|
+
@param {string} up-target
|
526
496
|
The selector to [replace](/up.replace) if the form submission is successful (200 status code).
|
527
|
-
@param {
|
497
|
+
@param {string} [up-fail-target]
|
528
498
|
The selector to [replace](/up.replace) if the form submission is not successful (non-200 status code).
|
529
499
|
If omitted, Unpoly will replace the `<form>` tag itself, assuming that the
|
530
500
|
server has echoed the form with validation errors.
|
531
501
|
@param [up-fallback]
|
532
502
|
The selector to replace if the server responds with a non-200 status code.
|
533
|
-
@param {
|
503
|
+
@param {string} [up-transition]
|
534
504
|
The animation to use when the form is replaced after a successful submission.
|
535
|
-
@param {
|
505
|
+
@param {string} [up-fail-transition]
|
536
506
|
The animation to use when the form is replaced after a failed submission.
|
537
507
|
@param [up-history]
|
538
508
|
Whether to push a browser history entry after a successful form submission.
|
@@ -542,27 +512,27 @@ up.form = (($) ->
|
|
542
512
|
|
543
513
|
Set this to `'false'` to prevent the URL bar from being updated.
|
544
514
|
Set this to a URL string to update the history with the given URL.
|
545
|
-
@param {
|
515
|
+
@param {string} [up-method]
|
546
516
|
The HTTP method to be used to submit the form (`get`, `post`, `put`, `delete`, `patch`).
|
547
517
|
Alternately you can use an attribute `data-method`
|
548
518
|
([Rails UJS](https://github.com/rails/jquery-ujs/wiki/Unobtrusive-scripting-support-for-jQuery))
|
549
519
|
or `method` (vanilla HTML) for the same purpose.
|
550
|
-
@param {
|
520
|
+
@param {string} [up-layer='auto']
|
551
521
|
The name of the layer that ought to be updated. Valid values are
|
552
522
|
`auto`, `page`, `modal` and `popup`.
|
553
523
|
|
554
524
|
If set to `auto` (default), Unpoly will try to find a match in the form's layer.
|
555
525
|
If no match was found in that layer,
|
556
526
|
Unpoly will search in other layers, starting from the topmost layer.
|
557
|
-
@param {
|
527
|
+
@param {string} [up-fail-layer='auto']
|
558
528
|
The name of the layer that ought to be updated if the server sends a
|
559
529
|
non-200 status code.
|
560
|
-
@param {
|
530
|
+
@param {string} [up-reveal='true']
|
561
531
|
Whether to reveal the target element within its viewport before updating.
|
562
|
-
@param {
|
532
|
+
@param {string} [up-restore-scroll='false']
|
563
533
|
Whether to restore previously known scroll position of all viewports
|
564
534
|
within the target selector.
|
565
|
-
@param {
|
535
|
+
@param {string} [up-cache]
|
566
536
|
Whether to force the use of a cached response (`true`)
|
567
537
|
or never use the cache (`false`)
|
568
538
|
or make an educated guess (`undefined`).
|
@@ -712,8 +682,8 @@ up.form = (($) ->
|
|
712
682
|
In order to update the `department` field in addition to the `employee` field, you could say
|
713
683
|
`up-validate="&, [name=employee]"`, or simply `up-validate="form"` to update the entire form.
|
714
684
|
|
715
|
-
@selector [up-validate]
|
716
|
-
@param {
|
685
|
+
@selector input[up-validate]
|
686
|
+
@param {string} up-validate
|
717
687
|
The CSS selector to update with the server response.
|
718
688
|
|
719
689
|
This defaults to a fieldset or form group around the validating field.
|
@@ -723,11 +693,11 @@ up.form = (($) ->
|
|
723
693
|
validate($field)
|
724
694
|
|
725
695
|
###*
|
726
|
-
Show or hide
|
696
|
+
Show or hide elements when a `<select>` or `<input>` has a given value.
|
727
697
|
|
728
|
-
\#\#\# Example
|
698
|
+
\#\#\# Example: Select options
|
729
699
|
|
730
|
-
The
|
700
|
+
The controlling form field gets an `up-switch` attribute with a selector for the elements to show or hide:
|
731
701
|
|
732
702
|
<select name="advancedness" up-switch=".target">
|
733
703
|
<option value="basic">Basic parts</option>
|
@@ -735,7 +705,8 @@ up.form = (($) ->
|
|
735
705
|
<option value="very-advanced">Very advanced parts</option>
|
736
706
|
</select>
|
737
707
|
|
738
|
-
The target elements
|
708
|
+
The target elements can use [`[up-show-for]`](/up-show-for) and [`[up-hide-for]`](/up-hide-for)
|
709
|
+
attributes to indicate for which values they should be shown or hidden:
|
739
710
|
|
740
711
|
<div class="target" up-show-for="basic">
|
741
712
|
only shown for advancedness = basic
|
@@ -749,63 +720,66 @@ up.form = (($) ->
|
|
749
720
|
shown for advancedness = advanced or very-advanced
|
750
721
|
</div>
|
751
722
|
|
752
|
-
|
723
|
+
\#\#\# Example: Text field
|
753
724
|
|
754
|
-
|
725
|
+
The controlling `<input>` gets an `up-switch` attribute with a selector for the elements to show or hide:
|
755
726
|
|
756
|
-
<
|
757
|
-
|
727
|
+
<input type="text" name="user" up-switch=".target">
|
728
|
+
|
729
|
+
<div class="target" up-show-for="alice">
|
730
|
+
only shown for user alice
|
758
731
|
</div>
|
759
732
|
|
760
733
|
You can also use the pseudo-values `:blank` to match an empty input value,
|
761
734
|
or `:present` to match a non-empty input value:
|
762
735
|
|
763
|
-
<input type="text" name="
|
736
|
+
<input type="text" name="user" up-switch=".target">
|
764
737
|
|
765
738
|
<div class="target" up-show-for=":blank">
|
766
|
-
please enter
|
739
|
+
please enter a username
|
767
740
|
</div>
|
768
741
|
|
769
|
-
|
770
|
-
@stable
|
771
|
-
###
|
742
|
+
\#\#\# Example: Checkbox
|
772
743
|
|
773
|
-
|
774
|
-
Show this element only if a form field has a given value.
|
744
|
+
For checkboxes you can match against the pseudo-values `:checked` or `:unchecked`:
|
775
745
|
|
776
|
-
|
746
|
+
<input type="checkbox" name="flag" up-switch=".target">
|
777
747
|
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
@stable
|
782
|
-
###
|
748
|
+
<div class="target" up-show-for=":checked">
|
749
|
+
only shown when checkbox is checked
|
750
|
+
</div>
|
783
751
|
|
784
|
-
|
785
|
-
|
752
|
+
<div class="target" up-show-for=":cunhecked">
|
753
|
+
only shown when checkbox is unchecked
|
754
|
+
</div>
|
755
|
+
|
756
|
+
Of course you can also match against the `value` property of the checkbox element:
|
786
757
|
|
787
|
-
|
758
|
+
<input type="checkbox" name="flag" value="active" up-switch=".target">
|
788
759
|
|
789
|
-
|
790
|
-
|
791
|
-
|
760
|
+
<div class="target" up-show-for="active">
|
761
|
+
only shown when checkbox is checked
|
762
|
+
</div>
|
763
|
+
|
764
|
+
@selector input[up-switch]
|
765
|
+
@param {string} up-switch
|
766
|
+
A CSS selector for elements whose visibility depends on this field's value.
|
792
767
|
@stable
|
793
768
|
###
|
794
|
-
|
795
|
-
up.on 'change', '[up-switch]', (event, $field) ->
|
769
|
+
up.compiler '[up-switch]', ($field) ->
|
796
770
|
switchTargets($field)
|
797
771
|
|
798
|
-
up.
|
772
|
+
up.on 'change', '[up-switch]', (event, $field) ->
|
799
773
|
switchTargets($field)
|
800
774
|
|
801
775
|
up.compiler '[up-show-for]:not(.up-switched), [up-hide-for]:not(.up-switched)', ($element) ->
|
802
776
|
switchTarget($element)
|
803
777
|
|
804
|
-
|
805
778
|
###*
|
806
|
-
Observes this field
|
779
|
+
Observes this field and runs a callback when a value changes.
|
807
780
|
|
808
781
|
This is useful for observing text fields while the user is typing.
|
782
|
+
If you want to submit the form after a change see [`input[up-autosubmit]`](/input-up-autosubmit).
|
809
783
|
|
810
784
|
The programmatic variant of this is the [`up.observe()`](/up.observe) function.
|
811
785
|
|
@@ -818,7 +792,35 @@ up.form = (($) ->
|
|
818
792
|
<input name="query" up-observe="showSuggestions(value)">
|
819
793
|
</form>
|
820
794
|
|
821
|
-
|
795
|
+
\#\#\# Callback context
|
796
|
+
|
797
|
+
The script given to `up-observe` runs with the following context:
|
798
|
+
|
799
|
+
| Name | Type | Description |
|
800
|
+
| -------- | --------- | ------------------------------------- |
|
801
|
+
| `value` | `string` | The current value of the field |
|
802
|
+
| `this` | `Element` | The form field |
|
803
|
+
| `$field` | `jQuery` | The form field as a jQuery collection |
|
804
|
+
|
805
|
+
@selector input[up-observe]
|
806
|
+
@param {string} up-observe
|
807
|
+
The code to run when the field's value changes.
|
808
|
+
@param {string} up-delay
|
809
|
+
The number of miliseconds to wait after a change before the code is run.
|
810
|
+
@stable
|
811
|
+
###
|
812
|
+
|
813
|
+
###*
|
814
|
+
Observes this form and runs a callback when any field changes.
|
815
|
+
|
816
|
+
This is useful for observing text fields while the user is typing.
|
817
|
+
If you want to submit the form after a change see [`input[up-autosubmit]`](/input-up-autosubmit).
|
818
|
+
|
819
|
+
The programmatic variant of this is the [`up.observe()`](/up.observe) function.
|
820
|
+
|
821
|
+
\#\#\# Example
|
822
|
+
|
823
|
+
The would call a function `somethingChanged(value)`
|
822
824
|
when any `<input>` within the `<form>` changes:
|
823
825
|
|
824
826
|
<form up-observe="somethingChanged(value)">
|
@@ -832,47 +834,62 @@ up.form = (($) ->
|
|
832
834
|
|
833
835
|
| Name | Type | Description |
|
834
836
|
| -------- | --------- | ------------------------------------- |
|
835
|
-
| `value` | `
|
837
|
+
| `value` | `string` | The current value of the field |
|
836
838
|
| `this` | `Element` | The form field |
|
837
839
|
| `$field` | `jQuery` | The form field as a jQuery collection |
|
838
840
|
|
839
|
-
@selector [up-observe]
|
840
|
-
@param {
|
841
|
-
The code to run when
|
842
|
-
@param {
|
841
|
+
@selector form[up-observe]
|
842
|
+
@param {string} up-observe
|
843
|
+
The code to run when any field's value changes.
|
844
|
+
@param {string} up-delay
|
843
845
|
The number of miliseconds to wait after a change before the code is run.
|
844
846
|
@stable
|
845
847
|
###
|
846
848
|
up.compiler '[up-observe]', ($formOrField) -> observe($formOrField)
|
847
849
|
|
848
850
|
###*
|
849
|
-
[Observes](/up.observe) this field
|
851
|
+
[Observes](/up.observe) this form field and submits the form when its value changes.
|
850
852
|
|
851
|
-
|
852
|
-
while the autosubmitted form is
|
853
|
+
Both the form and the changed field will be assigned a CSS class [`up-active`](/form-up-active)
|
854
|
+
while the autosubmitted form is loading.
|
853
855
|
|
854
856
|
The programmatic variant of this is the [`up.autosubmit()`](/up.autosubmit) function.
|
855
857
|
|
856
858
|
\#\#\# Example
|
857
859
|
|
858
|
-
The following would submit the form when
|
860
|
+
The following would automatically submit the form when the query is changed:
|
859
861
|
|
860
|
-
<form method="GET" action="/search"
|
861
|
-
<input type="search" name="query">
|
862
|
+
<form method="GET" action="/search">
|
863
|
+
<input type="search" name="query" up-autosubmit>
|
862
864
|
<input type="checkbox" name="archive"> Include archive
|
863
865
|
</form>
|
864
866
|
|
865
|
-
|
866
|
-
|
867
|
+
@selector input[up-autosubmit]
|
868
|
+
@param {string} up-delay
|
869
|
+
The number of miliseconds to wait after a change before the form is submitted.
|
870
|
+
@stable
|
871
|
+
###
|
867
872
|
|
868
|
-
|
869
|
-
|
873
|
+
###*
|
874
|
+
[Observes](/up.observe) this form and submits the form when *any* field changes.
|
875
|
+
|
876
|
+
Both the form and the field will be assigned a CSS class [`up-active`](/form-up-active)
|
877
|
+
while the autosubmitted form is loading.
|
878
|
+
|
879
|
+
The programmatic variant of this is the [`up.autosubmit()`](/up.autosubmit) function.
|
880
|
+
|
881
|
+
\#\#\# Example
|
882
|
+
|
883
|
+
This will submit the form when either query or checkbox was changed:
|
884
|
+
|
885
|
+
<form method="GET" action="/search" up-autosubmit>
|
886
|
+
<input type="search" name="query">
|
870
887
|
<input type="checkbox" name="archive"> Include archive
|
871
888
|
</form>
|
872
889
|
|
873
|
-
@selector [up-autosubmit]
|
874
|
-
@param {
|
875
|
-
The number of miliseconds to wait after
|
890
|
+
@selector form[up-autosubmit]
|
891
|
+
@param {string} up-delay
|
892
|
+
The number of miliseconds to wait after a change before the form is submitted.
|
876
893
|
@stable
|
877
894
|
###
|
878
895
|
up.compiler '[up-autosubmit]', ($formOrField) -> autosubmit($formOrField)
|