pure.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * FormValidation (http://formvalidation.io)
  3. * The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit and custom frameworks
  4. *
  5. * @author https://twitter.com/formvalidation
  6. * @copyright (c) 2013 - 2016 Nguyen Huu Phuoc
  7. * @license http://formvalidation.io/license/
  8. */
  9. /**
  10. * This class supports validating Pure framework (http://purecss.io/)
  11. */
  12. (function($) {
  13. FormValidation.Framework.Pure = function(element, options) {
  14. options = $.extend(true, {
  15. button: {
  16. selector: '[type="submit"]:not([formnovalidate])',
  17. // The class of disabled button
  18. // http://purecss.io/buttons/#disabled-buttons
  19. disabled: 'pure-button-disabled'
  20. },
  21. err: {
  22. clazz: 'fv-help-block',
  23. parent: '^.*pure-control-group.*$'
  24. },
  25. // Pure doesn't support feedback icon
  26. icon: {
  27. valid: null,
  28. invalid: null,
  29. validating: null,
  30. feedback: 'fv-control-feedback'
  31. },
  32. row: {
  33. // http://purecss.io/forms/#aligned-form
  34. selector: '.pure-control-group',
  35. valid: 'fv-has-success',
  36. invalid: 'fv-has-error',
  37. feedback: 'fv-has-feedback'
  38. }
  39. }, options);
  40. FormValidation.Base.apply(this, [element, options]);
  41. };
  42. FormValidation.Framework.Pure.prototype = $.extend({}, FormValidation.Base.prototype, {
  43. /**
  44. * Specific framework might need to adjust the icon position
  45. *
  46. * @param {jQuery} $field The field element
  47. * @param {jQuery} $icon The icon element
  48. */
  49. _fixIcon: function($field, $icon) {
  50. var ns = this._namespace,
  51. type = $field.attr('type'),
  52. field = $field.attr('data-' + ns + '-field'),
  53. $parent = $field.parent();
  54. if ('checkbox' === type || 'radio' === type) {
  55. if ($parent.is('label')) {
  56. $icon.insertAfter($parent);
  57. }
  58. }
  59. }
  60. });
  61. }(jQuery));