Log in

hypeAjax

hypeAjax

Utilities for AJAX requests

  • Deferred view rendering

Usage

Deferred view rendering

To defer view rendering, simply add 'deferred' => true to view vars.

echo elgg_view('my_view', [
    // tells the view system to defer view render
    'deferred' => true,

    // if set to false, placeholder will not be rendered
    // if set to a value, that value will be used as the placeholder
    // if not set, default ajax loader will be used
    'placeholder' => false,

    // you can pass other view vars, as you would with normal views
    // various Elgg data will be serialized and available to the deferred view
    // some of the values may need to be wrapped into a Serializable instance
    'entity' => get_entity(123),
    'user' => get_user(234),
]);

Ajax Forms

ajax/Form AMD module can be used to chain promise-based submit callbacks and submit the form via Ajax.

var Form = require('ajax/Form');
var form = new Form('.my-form');
var Ajax = require('elgg/Ajax');

form.onSubmit(function(resolve, reject) {
    // execute a long running script, e.g. validate fields via ajax
    var ajax = new Ajax();
    ajax.post('somewhere').done(resolve).fail(reject);
})

form.onSubmit(function(resolve, reject) {
    console.log('hello');
    resolve();
});


// By default, once all promises are resolved, the form will be submitted via ajax,
// and the user will be forwarded to the URL specified by the response
// You can however register custom success callbacks to prevent redirection

form.onSuccess(function(data) {
    console.log(data);

    require('elgg/lightbox', function(lightbox) {
        lightbox.close();
    });

    $('.my-list').refresh();
});

// You can also add your own error handler

form.onError(function(error) {
    console.log(error);
});

Package Releases

VersionRelease Date
hypeAjax 1.2.11.2.1
hypeAjax 1.2.01.2.0
hypeAjax 1.1.01.1.0
hypeAjax 1.0.21.0.2
hypeAjax 1.0.11.0.1
hypeAjax 1.0.01.0.0

Changelog

1.2.0 (2018-07-06)

Features

  • forms: adds promise-based ajax form api (c056cb8)

1.1.0 (2018-06-29)

Bug Fixes

  • ajax: correctly pass unserialized values to views (4fb65b7)
  • routes: restrict route to ajax requests (13ffee3)

Features

1.0.2 (2018-04-26)

Bug Fixes

  • routes: restrict route to ajax requests (13ffee3)

1.0.1 (2018-04-26)

Bug Fixes

  • ajax: correctly pass unserialized values to views (4fb65b7)

1.0.0 (2018-03-19)

Features

  • releases: initial commit (aaa8156)

About

Dependencies

Requires
Elgg version >= 3.0