can i change the display of the error message ,i want it to be displayed beside the text field just like in username check module..

Comments

brendoncrawford’s picture

Assigned: Unassigned » brendoncrawford
Status: Active » Fixed

I have added the ability to do this in 1.x-6.x-dev. Please allow up to 12 hours for the dev package to update. You will need to make your own javascript plugin using the 'message' hook. Be sure to return false to disable the standard message handling.

Here is an example usage....

Drupal.Ajax.plugins.myPlugin = function(hook, args) {
  if (hook === 'message') {
    if (args.options.action === 'notify') {
      for (i = 0, _i = args.options.messages.length; i < _i; i++) {
        alert(args.options.messages[i].value);
      }
    }
    return false;
  }
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

szantog’s picture

Component: Code » Documentation
Category: task » support
Status: Closed (fixed) » Active

Sorry, to reopen this old issue, but I tried to use exactly this function.

I made the core-s login form ajaxify, when wrong username or password i get the error message before the form, i need to write it after the form elements

1. I made my module, use the preprocess_page to add my js.
2. The js contains the code in #1, and i see it in page head
3. I tried to explore the args.options in DOM, stopped the running in line: Drupal.Ajax.writeMessage(args.formObj, args.submitter, args.options); But I cant get, what need I modify.

How can i configure the options, to move error message after the form?

The html is:

<form class="ajax-form" id="user-login-form" method="post" accept-charset="UTF-8" action="/node?destination=node">

<div class="messages error">error</div>

<div>
  <div id="edit-name-wrapper" class="form-item">.</div>
     .. the form content
   </div>
</div>
</form>

I need to get this html:

<form class="ajax-form" id="user-login-form" method="post" accept-charset="UTF-8" action="/node?destination=node">
<div>
  <div id="edit-name-wrapper" class="form-item">.</div>
     .. the form content
  </div>
</div>

<div class="messages error">error</div>

</form>
szantog’s picture

Hmm, I don't know, I've just started to learn the jquery + drupal js system because of this task.
I solved it, but I don't know, is this the correct way?

Drupal.Ajax.plugins.myPlugin = function(hook, args) {
  if (hook === 'message') {
    var i, _i, thisItem, log, errBox, h, data, type;
	
   if (args.messages_error) {
     type = 'error'
     log = $('<ul>');
     errBox = $(".messages." + type, args.local.form[0])
      for (i = 0, _i = args.messages_error.length; i < _i; i++) {
        thisItem = $('#' + args.messages_error[i].id, args.local.form[0])
        thisItem.addClass(type);
        if (args.messages_error[i].required) {
          thisItem.addClass('required');
        }
        log.append('<li>' + args.messages_error[i].value + '</li>');
    }
    if (errBox.length === 0) {
      errBox = $("<div class='messages " + type + "'>");
      errBox.html(log);
      args.local.form.after(errBox);
    }
  return false;
  }  
  }
}