Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /** * @file * Contains Drupalajax_exampleAjaxExampleForm */
- namespace Drupalajax_exampleForm;
- use Drupalajax_exampleAjaxAjaxExampleCommand; use DrupalCoreAjaxAjaxResponse;
- use DrupalCoreAjaxCommandInterface;
- use DrupalCoreAjaxChangedCommand;
- use DrupalCoreAjaxCssCommand;
- use DrupalCoreAjaxHtmlCommand;
- use DrupalCoreAjaxInvokeCommand;
- use DrupalCoreFormFormBase;
- use DrupalCoreFormFormStateInterface;
- class AjaxExampleForm extends FormBase{
- /**
- * @param array $form
- * @param FormStateInterface $form_state
- *
- * @return array
- */
- public function buildForm(array $form, FormStateInterface $form_state) {
- $form['submit'] = array(
- '#type' => 'button',
- '#value' => 'Login',
- '#attached' => array(
- 'library' => array(
- 'ajax_example/ajaxCustom','core/jquery')),
- '#ajax' => array(
- 'callback' => 'Drupalajax_exampleFormAjaxExampleForm::ajaxCallOwn',
- 'event' => 'click',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => 'ajaxOwn',
- ),
- ));
- }
- public function ajaxCallOwn(array &$form, FormStateInterface $form_state)
- {
- $ajax_response = new AjaxResponse();
- //$ajax_response->addCommand(new HtmlCommand('#edit-user-name2--description', "changedDessrition!!!!"));
- $ajax_response->addCommand(new InvokeCommand(NULL,'changeDescription'));
- return $ajax_response;
- }
- <?php
- /**
- * @file
- * Contains Drupalajax_exampleAjaxAjaxExampleCommand
- */
- namespace Drupalajax_exampleAjax;
- use DrupalCoreAjaxCommandInterface;
- class AjaxExampleCommand implements CommandInterface{
- /**
- * @var string
- */
- protected $blub;
- // Constructs a SystemBlubCommand object.
- /**
- * Constructs an SlideDownCommand object.
- * @param string $blub
- */
- public function __construct() {
- $this->blub = "changed!!!!";
- }
- public function render() {
- return array(
- 'command' => 'changeDescription',
- 'method' => NULL,
- 'blub' => $this->blub,
- );
- }
- }
- (function ($, Drupal) {
- /**
- * Command to Slide Down page elements before removing them.
- *
- * @param {Drupal.Ajax} [ajax]
- * @param {object} response
- * @param {string} response.blub
- * @param {number} [status]
- */
- Drupal.AjaxCommands.prototype.changeDescription = function (ajax, response, status) {
- alert("asdfasdgf");
- $("#edit-user-name--description").remove();
- $("#edit-user-name--description").html(response.blub);
- };
- })(jQuery, Drupal);
- ajax_example:
- version: 1.x
- js:
- js/ajaxCustom.js: {}
- dependencies:
- - core/drupal
- - core/drupal.ajax
- - core/jquery
Add Comment
Please, Sign In to add comment