0

Are there any helper functions contained in Drupal core or Ctools to perform popular tasks such as clearing input field after an event occurs ? I know how to do it using external js (javascript) file, but I was wondering whether an alternative way for this exists or not ?

4

I doubt it, that would be re-inventing the wheel IMO...what you're describing is pretty much what jQuery is for. Consider this code, which is a basic representation of what you're trying to do:

$(function() {
  $('#some-element').bind('someEvent', function() {
    $('#some-other-element').val('');
  });
});

That's only 3 meaningful lines of code, and is so trivial that writing a function to wrap around it would be counter-intuitive. The resulting code would end up being equally or more verbose, and all it would do is basically pass parameters blindly to a jQuery function.

Don't forget if you want to invoke any Javascript at all you're going to need an external JS file (or at the very least inline code). I would suggest using the above 3 lines in that external/inline JS would be preferable to using any sort of wrapper function (even if one does exist).

0

With reference to your question 'Clear input field after click without attach any external script', possibly this will work ::

  1. Consider the url http://campusdiaries.com/
  2. Here, consider Email & School/College/Org fields on home page (for registration)

Here, we have used below form elements ::

'#attributes' =>array('placeholder' => t('Email')) '#attributes' =>array('placeholder' => t('School/College/Org'))

Here, input field gets cleaned on mouse down.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.