Index: trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/validate.js |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | * |
9 | 9 | * @since r100950 |
10 | 10 | */ |
11 | | - |
| 11 | + |
12 | 12 | /******************************************************************************* |
13 | 13 | |
14 | 14 | Helpers |
— | — | @@ -93,9 +93,6 @@ |
94 | 94 | else { |
95 | 95 | params.min = 0; |
96 | 96 | } |
97 | | - //console.log('value: ' + value); |
98 | | - //console.log('integerValue: ' + integerValue); |
99 | | - //console.log(params); |
100 | 97 | |
101 | 98 | return integerValue >= params.min; |
102 | 99 | }, mw.msg( 'donate_interface-error-msg-invalid-amount' ) ); |
— | — | @@ -383,187 +380,170 @@ |
384 | 381 | *******************************************************************************/ |
385 | 382 | |
386 | 383 | /** |
387 | | - * Validate Bank Transfers |
| 384 | + * Validate GlobalCollect payment forms |
| 385 | + * |
| 386 | + * See how to implement error containers |
| 387 | + * @link http://jquery.bassistance.de/validate/demo/errorcontainer-demo.html |
388 | 388 | * |
| 389 | + * Notes: |
| 390 | + * - To make cancel buttons not attempt form validation, add class="cancel" to the button element. |
| 391 | + * - Validation does not ignore hidden fields. |
| 392 | + * - This attaches a listener for a form submit event. When the form is submitted, it is captured and validated. |
389 | 393 | */ |
| 394 | +$().ready(function() { |
390 | 395 | |
391 | | -function validateForm( options ) { |
392 | | -/* |
393 | | - $("#form1").validate({ |
394 | | - errorLabelContainer: $("#form1 div.error") |
395 | | - }); |
| 396 | + if ( !isset( validatePaymentForm.formId ) ) { |
| 397 | + validatePaymentForm.formId = ''; |
| 398 | + } |
| 399 | + |
| 400 | + if ( empty( validatePaymentForm.formId ) ) { |
| 401 | + |
| 402 | + // An id must be specified to validate the form. |
| 403 | + return; |
| 404 | + } |
| 405 | + |
| 406 | + // Options for plugin jquery.validate.js |
| 407 | + var validateOptions = { |
| 408 | + //ignore: ':hidden', |
| 409 | + } |
396 | 410 | |
397 | | - var container = $('div.container'); |
398 | | - // validate the form when it is submitted |
399 | | - var validator = $("#form2").validate({ |
400 | | - errorContainer: container, |
401 | | - errorLabelContainer: $("ol", container), |
402 | | - wrapper: 'li', |
403 | | - meta: "validate" |
404 | | - }); |
| 411 | + /* |
| 412 | + * This is where everything happens: .validate( validateOptions ); |
| 413 | + */ |
| 414 | + $("#" + validatePaymentForm.formId).validate( validateOptions ); |
| 415 | + |
| 416 | + // Check for payment_method |
| 417 | + if ( !isset( validatePaymentForm.payment_method ) ) { |
| 418 | + validatePaymentForm.payment_method = ''; |
| 419 | + } |
| 420 | + |
| 421 | + // Check for payment_submethod |
| 422 | + if ( !isset( validatePaymentForm.payment_submethod ) ) { |
| 423 | + validatePaymentForm.payment_submethod = ''; |
| 424 | + } |
| 425 | + |
| 426 | + // Initialize validate options if not set. |
| 427 | + if ( !isset( validatePaymentForm.validate ) ) { |
| 428 | + validatePaymentForm.validate = {}; |
| 429 | + } |
| 430 | + |
| 431 | + /* |
| 432 | + * Setup default validations based on payment_method |
| 433 | + */ |
405 | 434 | |
406 | | - $(".cancel").click(function() { |
407 | | - validator.resetForm(); |
408 | | - }); |
| 435 | + if ( validatePaymentForm.payment_method == 'cc' ) { |
| 436 | + |
| 437 | + // card_num and cvv are not validated on our site. |
| 438 | + } |
| 439 | + else if ( validatePaymentForm.payment_method == 'bt' ) { |
| 440 | + |
| 441 | + validatePaymentForm.validate.payment = true; |
| 442 | + } |
| 443 | + else if ( validatePaymentForm.payment_method == 'rtbt' ) { |
| 444 | + |
| 445 | + validatePaymentForm.validate.payment = true; |
| 446 | + } |
409 | 447 | |
410 | | -*/ |
411 | | - $().ready(function() { |
| 448 | + /* |
| 449 | + * Setup default validations based on payment_submethod |
| 450 | + */ |
412 | 451 | |
413 | | - if ( !isset( options.formId ) ) { |
414 | | - options.formId = ''; |
415 | | - } |
416 | | - |
417 | | - if ( empty( options.formId ) ) { |
418 | | - |
419 | | - // An id must be specified to validate the form. |
420 | | - return; |
421 | | - } |
422 | | - |
423 | | - var validateOptions = { |
424 | | - ignore: ':hidden', |
425 | | - } |
| 452 | + if ( validatePaymentForm.payment_submethod == 'rtbt_ideal' ) { |
426 | 453 | |
427 | | - $("#" + options.formId).validate(); |
| 454 | + // Ideal requires issuer_id |
| 455 | + validatePaymentForm.validate.issuerId = true; |
| 456 | + } |
| 457 | + else if ( validatePaymentForm.payment_submethod == 'rtbt_eps' ) { |
| 458 | + |
| 459 | + // eps requires issuer_id |
| 460 | + validatePaymentForm.validate.issuerId = true; |
| 461 | + } |
428 | 462 | |
429 | | - // Check for payment_method |
430 | | - if ( !isset( options.payment_method ) ) { |
431 | | - options.payment_method = ''; |
432 | | - } |
| 463 | + /* |
| 464 | + * Standard elements groups to validate |
| 465 | + */ |
433 | 466 | |
434 | | - // Check for payment_submethod |
435 | | - if ( !isset( options.payment_submethod ) ) { |
436 | | - options.payment_submethod = ''; |
437 | | - } |
| 467 | + // Options: Validate address |
| 468 | + if ( !isset( validatePaymentForm.validate.address ) ) { |
| 469 | + validatePaymentForm.validate.address = true; |
| 470 | + } |
438 | 471 | |
439 | | - //console.log( options ); |
440 | | - // Initialize validate options if not set. |
441 | | - if ( !isset( options.validate ) ) { |
442 | | - options.validate = {}; |
443 | | - } |
444 | | - //console.log( options.validate ); |
| 472 | + // Options: Validate amount |
| 473 | + if ( !isset( validatePaymentForm.validate.amount ) ) { |
| 474 | + validatePaymentForm.validate.amount = true; |
| 475 | + } |
445 | 476 | |
446 | | - /* |
447 | | - * Setup default validations based on payment_method |
448 | | - */ |
449 | | - |
450 | | - if ( options.payment_method == 'cc' ) { |
451 | | - |
452 | | - // card_num and cvv are not validated on our site. |
453 | | - } |
454 | | - else if ( options.payment_method == 'bt' ) { |
455 | | - |
456 | | - options.validate.payment = true; |
457 | | - } |
458 | | - else if ( options.payment_method == 'rtbt' ) { |
459 | | - |
460 | | - options.validate.payment = true; |
461 | | - } |
462 | | - //console.log( options.validate ); |
| 477 | + // Options: Validate creditCard |
| 478 | + if ( !isset( validatePaymentForm.validate.creditCard ) ) { |
| 479 | + validatePaymentForm.validate.creditCard = false; |
| 480 | + } |
463 | 481 | |
464 | | - /* |
465 | | - * Setup default validations based on payment_submethod |
466 | | - */ |
467 | | - |
468 | | - if ( options.payment_submethod == 'rtbt_ideal' ) { |
469 | | - |
470 | | - // Ideal requires issuer_id |
471 | | - options.validate.issuerId = true; |
472 | | - } |
473 | | - else if ( options.payment_submethod == 'rtbt_eps' ) { |
474 | | - |
475 | | - // eps requires issuer_id |
476 | | - options.validate.issuerId = true; |
477 | | - } |
478 | | - //console.log( options.validate ); |
| 482 | + // Options: Validate email |
| 483 | + if ( !isset( validatePaymentForm.validate.email ) ) { |
| 484 | + validatePaymentForm.validate.email = true; |
| 485 | + } |
479 | 486 | |
480 | | - /* |
481 | | - * Standard elements groups to validate |
482 | | - */ |
483 | | - |
484 | | - // Options: Validate address |
485 | | - if ( !isset( options.validate.address ) ) { |
486 | | - options.validate.address = true; |
487 | | - } |
488 | | - |
489 | | - // Options: Validate amount |
490 | | - if ( !isset( options.validate.amount ) ) { |
491 | | - options.validate.amount = true; |
492 | | - } |
493 | | - |
494 | | - // Options: Validate creditCard |
495 | | - if ( !isset( options.validate.creditCard ) ) { |
496 | | - options.validate.creditCard = false; |
497 | | - } |
498 | | - |
499 | | - // Options: Validate email |
500 | | - if ( !isset( options.validate.email ) ) { |
501 | | - options.validate.email = true; |
502 | | - } |
503 | | - |
504 | | - // Options: Validate issuerId |
505 | | - if ( !isset( options.validate.issuerId ) ) { |
506 | | - options.validate.issuerId = false; |
507 | | - } |
508 | | - |
509 | | - // Options: Validate name |
510 | | - if ( !isset( options.validate.name ) ) { |
511 | | - options.validate.name = true; |
512 | | - } |
513 | | - |
514 | | - // Options: Validate payment |
515 | | - if ( !isset( options.validate.payment ) ) { |
516 | | - options.validate.payment = false; |
517 | | - } |
518 | | - //console.log( options.validate ); |
| 487 | + // Options: Validate issuerId |
| 488 | + if ( !isset( validatePaymentForm.validate.issuerId ) ) { |
| 489 | + validatePaymentForm.validate.issuerId = false; |
| 490 | + } |
519 | 491 | |
520 | | - /* |
521 | | - * Standard elements groups to validate if enabled |
522 | | - */ |
| 492 | + // Options: Validate name |
| 493 | + if ( !isset( validatePaymentForm.validate.name ) ) { |
| 494 | + validatePaymentForm.validate.name = true; |
| 495 | + } |
| 496 | + |
| 497 | + // Options: Validate payment |
| 498 | + if ( !isset( validatePaymentForm.validate.payment ) ) { |
| 499 | + validatePaymentForm.validate.payment = false; |
| 500 | + } |
| 501 | + |
| 502 | + /* |
| 503 | + * Standard elements groups to validate if enabled |
| 504 | + */ |
| 505 | + |
| 506 | + // Validate: address |
| 507 | + if ( validatePaymentForm.validate.address ) { |
| 508 | + validateElementStreet( validatePaymentForm ); |
| 509 | + validateElementCity( validatePaymentForm ); |
| 510 | + validateElementState( validatePaymentForm ); |
| 511 | + validateElementCountry( validatePaymentForm ); |
523 | 512 | |
524 | | - // Validate: address |
525 | | - if ( options.validate.address ) { |
526 | | - validateElementStreet( options ); |
527 | | - validateElementCity( options ); |
528 | | - validateElementState( options ); |
529 | | - //validateElementZip( options ); |
530 | | - validateElementCountry( options ); |
531 | | - } |
532 | | - |
533 | | - // Validate: amount |
534 | | - if ( options.validate.amount ) { |
535 | | - validateElementAmount( options ); |
536 | | - } |
537 | | - |
538 | | - // Validate: creditCard |
539 | | - if ( options.validate.creditCard ) { |
540 | | - validateElementCardNumber( options ); |
541 | | - validateElementCvv( options ); |
542 | | - } |
543 | | - |
544 | | - // Validate: email |
545 | | - if ( options.validate.email ) { |
546 | | - validateElementEmail( options ); |
547 | | - } |
548 | | - |
549 | | - // Validate: name |
550 | | - if ( options.validate.name ) { |
551 | | - validateElementFirstName( options ); |
552 | | - validateElementLastName( options ); |
553 | | - } |
554 | | - |
555 | | - // Validate: payment |
556 | | - if ( options.validate.payment ) { |
557 | | - validateElementPaymentMethod( options ); |
558 | | - validateElementPaymentSubmethod( options ); |
559 | | - |
560 | | - // Validate: issuer_id |
561 | | - if ( options.validate.issuerId ) { |
562 | | - validateElementIssuerId( options ); |
563 | | - } |
564 | | - } |
565 | | - |
566 | | - // The following validators are not ready: |
| 513 | + // Zip is not ready |
| 514 | + //validateElementZip( validatePaymentForm ); |
| 515 | + } |
567 | 516 | |
568 | | - }); |
569 | | -} |
| 517 | + // Validate: amount |
| 518 | + if ( validatePaymentForm.validate.amount ) { |
| 519 | + validateElementAmount( validatePaymentForm ); |
| 520 | + } |
| 521 | + |
| 522 | + // Validate: creditCard |
| 523 | + if ( validatePaymentForm.validate.creditCard ) { |
| 524 | + validateElementCardNumber( validatePaymentForm ); |
| 525 | + validateElementCvv( validatePaymentForm ); |
| 526 | + } |
| 527 | + |
| 528 | + // Validate: email |
| 529 | + if ( validatePaymentForm.validate.email ) { |
| 530 | + validateElementEmail( validatePaymentForm ); |
| 531 | + } |
| 532 | + |
| 533 | + // Validate: name |
| 534 | + if ( validatePaymentForm.validate.name ) { |
| 535 | + validateElementFirstName( validatePaymentForm ); |
| 536 | + validateElementLastName( validatePaymentForm ); |
| 537 | + } |
| 538 | + |
| 539 | + // Validate: payment |
| 540 | + if ( validatePaymentForm.validate.payment ) { |
| 541 | + validateElementPaymentMethod( validatePaymentForm ); |
| 542 | + validateElementPaymentSubmethod( validatePaymentForm ); |
| 543 | + |
| 544 | + // Validate: issuer_id |
| 545 | + if ( validatePaymentForm.validate.issuerId ) { |
| 546 | + validateElementIssuerId( validatePaymentForm ); |
| 547 | + } |
| 548 | + } |
| 549 | +}); |
570 | 550 | |