1. If you're receiving a message that you are banned from the Current Events or Politics forums, it's not you specifically: those forums have been hidden for all users. For more info, see here.
    Dismiss Notice

A javascript framework I wrote

Discussion in 'Programming & Software Development' started by yoink, Oct 20, 2008.

  1. OP
    OP
    yoink

    yoink Member

    Joined:
    Feb 19, 2002
    Messages:
    3,510
    Checkboxes should have different names, whereas radios can be names the same. You can't capture seperate checkboxes ticked, if they have the same name... Sounds like you should be using radio buttons instead?
     
  2. n000b

    n000b Member

    Joined:
    Jul 4, 2002
    Messages:
    2,489
    Location:
    Melbourne
    I've always used checkboxes like this:

    Say I want to let a user select what they would like for lunch. They can select none or more of the following options: banana, apple, orange, chocolate. HTML would be:

    <option name="food[]" value="banana">Banana <option name="food[]" value="apple">Apple <option name="food[]" value="orange">Orange <option name="food[]" value="chocolate">Chocolate

    In PHP, food is accessible as an array in $_GET or $_POST, with only the options that were checked inside the array. So if I selected apple and chocolate, the array in PHP would look like:

    $_POST['food'] = array('apple', 'chocolate');

    If I select none of the foods, the array is empty and the variable $_POST['food'] does not exist.

    Is this not what I'm supposed to be doing? :Paranoid:
     
  3. OP
    OP
    yoink

    yoink Member

    Joined:
    Feb 19, 2002
    Messages:
    3,510
    Ah, I see what you mean now - that is a valid use case, though I haven't used PAX validation like that before with checkboxes. I'll raise it as a bug, and see when I can get a fix for it.
    Do you have example code I can use when testing?
     
  4. OP
    OP
    yoink

    yoink Member

    Joined:
    Feb 19, 2002
    Messages:
    3,510
    Ok, I've updated the dev version, it should do what you're after, can you please download it here:

    http://paxjs.com/pax/pax_dev.js

    and test against your code?
     
  5. FearTec

    FearTec Member

    Joined:
    Jul 22, 2003
    Messages:
    2,401
    Location:
    NSW
    Nice Work :)
     
  6. n000b

    n000b Member

    Joined:
    Jul 4, 2002
    Messages:
    2,489
    Location:
    Melbourne
    I just tried to download PaxJS from your website but the ZIP file is giving me heaps of CRC errors when I try to extract it (I tried downloading it twice, same thing).
     
  7. OP
    OP
    yoink

    yoink Member

    Joined:
    Feb 19, 2002
    Messages:
    3,510
    I haven't updated the zip file, try just the dev version I uploaded...
    I'll look into the zip file later...
     
  8. n000b

    n000b Member

    Joined:
    Jul 4, 2002
    Messages:
    2,489
    Location:
    Melbourne
    I remembered that I was using an old version of paxJS (1+ year ago) and I think you've updated it since then? So I was trying to download the new version to put your new dev file in to :)
     
  9. rockuman_ex

    rockuman_ex Member

    Joined:
    Apr 3, 2002
    Messages:
    3,873
    Location:
    Brisbane
    I didn't get any error?
     
  10. rockuman_ex

    rockuman_ex Member

    Joined:
    Apr 3, 2002
    Messages:
    3,873
    Location:
    Brisbane
    just tested that, it works :D
     
  11. OP
    OP
    yoink

    yoink Member

    Joined:
    Feb 19, 2002
    Messages:
    3,510
    Hmmm... the key difference is that I'm using a mac to zip it now, compared to a year ago, though it works fine on my PC...
    You should download the latest ZIP, and overwrite the pax_dev.js file with the one I linked to for testing...
     
  12. rm -rp ./Matt*

    rm -rp ./Matt* Member

    Joined:
    Sep 25, 2008
    Messages:
    621
    Location:
    in the computer
    Hey Yoink,
    Hows it going? I come to you with a question about your code, are the hints directly tied to form fields only or could they be used with javascript validation routines?

    Case in point, I've got alot of validation that gets repeated over and over again in different fields, eg form field 1, 3 and 5 all use javascript validation routine yyy to make sure they're correct(all have to equal 2). Now instead of adding the hint to each form - hint: Must equal 2 - is there a way to tie it to the validation routine yyy that gets called by valDict mask:yyy

    Hope that makes sense, have a good Xmas.
     
  13. OP
    OP
    yoink

    yoink Member

    Joined:
    Feb 19, 2002
    Messages:
    3,510
    First of all, sorry, I missed your post!

    Uh, so you want to repeat the same validation for a bunch of fields? The easiest way to do that is to define a validation mask in an object, and then simply repeat it for the relevant forms, like so:

    Code:
    <form name='one'>
    <input type='text' id='txt1' name='txt1'/>
    </form>
    
    <form name='two'>
    <input type='text' id='txt2' name='txt2'/>
    </form>
    
    <form name='three'>
    <input type='text' id='txt3' name='txt3'/>
    </form>
    
    <script>
    var txtVal = {
        mask: [
            { mask: 'len', minLen: '2', maxLen: '2' },
            { mask: 'notEmpty' }
        ],
        hint: 'Enter at 2 chars, and no more than 2 chars in this field' 
    };
    
    pax.load.onloaded( function() {
        pax.validate.initValidation( 'one', {
            'txt1': txtVal
        } );
    
        pax.validate.initValidation( 'one', {
            'txt2': txtVal
        } );
    
        pax.validate.initValidation( 'one', {
            'txt3': txtVal
        } );
    };
    
    </script>
    
    
    Is that what you're after?
     
  14. rm -rp ./Matt*

    rm -rp ./Matt* Member

    Joined:
    Sep 25, 2008
    Messages:
    621
    Location:
    in the computer
    Excellent it worked :D This way I can not only tie hints to validation, instead of the field but all the validation (numeric, length etc), thanks for the help!
     
  15. rockuman_ex

    rockuman_ex Member

    Joined:
    Apr 3, 2002
    Messages:
    3,873
    Location:
    Brisbane
    hi yoink... what happen to paxjs? :D
     
    Last edited: Feb 21, 2011

Share This Page

Advertisement: