jquery - Target specific submit button using bootstarp validator -



jquery - Target specific submit button using bootstarp validator -

my form has 2 submit buttons, 1 submits main form , other 1 sends info using ajax. can't figure out how tell bootstrap validator in case using different submit button. , yes on submit im using preventdefault();

$("#submitformat").click(function( event ) { $('#formid').bootstrapvalidator({ // id right message: 'this value not valid', fields: { alias: { message: 'the username not valid', validators: { notempty: { message: 'the username required , cannot empty' }, stringlength: { min: 6, max: 30, message: 'the username must more 6 , less 30 characters long' }, regexp: { regexp: /^[a-za-z0-9_]+$/, message: 'the username can consist of alphabetical, number , underscore' } } }, } });

html button:

<button type="submit" id="submitformat" class="btn btn-primary">submit</button>

accordig here have utilize submithandler alternative on bootstrapvalidator utilize ajax

taked link

using ajax submit form

in case want utilize ajax submit form , perform additional tasks after that, can utilize submithandler option.

regard our modal example, next code shows how to:

check if there business relationship given username , password sending them remote url via ajax request if yes, reload current page otherwise, show message informing business relationship not found

<script> $(document).ready(function() { $('#loginform').bootstrapvalidator({ message: 'this value not valid', feedbackicons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, submithandler: function(validator, form, submitbutton) { $.post(form.attr('action'), form.serialize(), function(result) { // result json formatted back-end // assume format following: // { // valid: true, // false if business relationship not found // username: 'username', // null if business relationship not found // } if (result.valid == true || result.valid == 'true') { // can reload current location window.location.reload(); // or utilize javascript update page, such showing business relationship name // $('#welcome').html('hello ' + result.username); } else { // business relationship not found // show errors $('#errors').html('the business relationship not found').removeclass('hide'); // enable submit buttons $('#loginform').bootstrapvalidator('disablesubmitbuttons', false); } }, 'json'); }, fields: { username: { validators: { notempty: { message: 'the username required' } } }, password: { validators: { notempty: { message: 'the password required' } } } } }); }); </script>

plus not neccessary overwrite .click() when button have sumbit (type of button)

jquery twitter-bootstrap

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -