简体   繁体   中英

jQuery: Form Validation plugin with Chosen and Step Wizard

Here is my JavaScript:

jQuery.validator.addMethod("ChznCheck", function(val, elem) {
  return $(elem).val();
}, "Required before continuing");

jQuery.validator.setDefaults({
  errorElement: 'span',
  onkeyup: false,
  onclick: false,
  onfocusout: false,
  onsubmit: false,
  focusCleanup: true,
  ignore: [],
  rules: {
    "user[username]": {
      required: true,
      remote: {
        url: '/check_username',
        type: 'post',
        data: {
          username: function() {
            return $('#user_username').val();
          }
        }
      }
    },
    "user[state]": {
      ChznCheck: true
    }
  },
  messages: {
    "user[username]": "Username unavailable, please try again"
  }
});

$(function(){
  var $form, wizard;

  wizard = $('#registrationWizard').wizard();

  $form = $('#finalize-form');

  if ($form.length) {
    wizard.on('change', function(e, data) {
      log($form.validate().form());
      if (!$form.validate().form()) {
        return e.preventDefault();
      }
    }).on('finished', function(e) {
      return $form.submit();
    });
  }
})

I am using the fuel UX wizard ( http://exacttarget.github.io/fuelux/#wizard ) and I am using the Chosen library ( http://harvesthq.github.io/chosen/ ) to "prettify" my select boxes. For some reason, when I get done filling out all fields in Step 1, and click Next, the form still fails, even though everything is filled out properly.

I am basically just trying to use the jQuery validation plugin ( http://jqueryvalidation.org/ ) along with chosen to be able to validate my form, but am having no success. Anyone else run into this issue?

找到了针对jQuery验证插件的请求请求: https : //github.com/jzaefferer/jquery-validation/pull/452

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM