User login

Pre-validation of forms with JQuery- alphanumeric check

pipit: i'm trying to validate (ex age) field on drupal form, using javascript. I found the jquery.alphanumeric.js, add it via drupal_add_js. But how to "insert" in on the age field ?
[12:23am] rszrama: pipit: alphanumeric = some jquery plugin?
[12:23am] pipit: rszrama : duno, i just try learn jquery stuff today :). I got it from : http://itgroup.com.ph/alphanumeric/
[12:25am] rszrama: I dig... it's not that hard. I assume you're writing a form in a custom module? if so, you should know the ID of the element you want to add the test to
[12:25am] rszrama: if the key to the element array in $form is this_key, the CSS ID will be #edit-this-key
[12:25am] rszrama: so, in your JS, create a document ready function that includes this line: $('#edit-this-key').alphanumeric();
[12:26am] rszrama: that's a pretty sweet plugin, btw
[12:26am] rszrama: could enhance some fields like node type and CCK field machine names
[12:27am] pipit: rszrama : you mean, i must do : 1th create 1 javascipt file again (said mynumeric.js) with that $... line, 2nd add it via drupal_add_js.
[12:27am] pipit: and just it?
[12:28am] pipit: no need to add something on the form['this-key'] ?
[12:28am] rszrama: well, you want to add the JS file via drupal_add_js(), but the line I posted should be in a document ready function
[12:28am] rszrama: you're working with 5.x, right?
[12:28am] pipit: yes
[12:29am] pipit: rszrama : np, i thought i can find the document ready function stuff.
[12:29am] rszrama: then yeah, use drupal_add_js on the form page; that JS file should be something like $(document).ready(function() { $('#edit-field-key').alphanumeric(); });
[12:29am] rszrama: preferable to use whitespace
[12:30am] rszrama: and look out! forms API converts _ in element keys to - in CSS IDs
[12:31am] vhmauery joined the chat room.
[12:32am] pipit: i'll try it rszrama. big thanks for your info. help me not wasting next 2 hour view source of html, how to make the form output like the sample
[12:34am] rszrama: hehe no problem
[12:34am] rszrama: jQuery is much fun
[12:34am] rszrama: (not as fun as Drupal, of course)

Unrelated, but what Agaric was working on that was helped by above conversation:

<pre>$(document).ready(function() {
  $('#place-taxonomy-terms-dropdown-form .form-submit').addClass('hide');
});</pre>

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.