javascript - Customizing a password strength validator plugin -



javascript - Customizing a password strength validator plugin -

i using plugin called pstrength.jquery.js , reason not submitting form have, or submitting form if not supposed (when changed code)

the code using is:

$(document).ready(function () { $('#myform').submit(function () { homecoming false; }); $('#myelement1, #myelement2').pstrength({ 'changebackground': false, 'onpasswordstrengthchanged': function (passwordstrength, strengthpercentage) { if ($(this).val()) { $.fn.pstrength('changebackground', this, passwordstrength); } else { $.fn.pstrength('resetstyle', this); } $('#' + $(this).data('display')).html('your password strength ' + strengthpercentage + '%'); }, 'onvalidatepassword': function (strengthpercentage) { $('#' + $(this).data('display')).html( $('#' + $(this).data('display')).html() + ' great, can go on alter password!'); $('#myform').submit(function () { homecoming true; }); } }); });

someone has told me should utilize booleans , within validation checks, set true or false.

the problem have no thought how this

is there help me , show me code this?

thank in advance

the reason still submitting because onvalidatepassword function runs on each individual field, whereas had 2 fields validate. if 1 field validates , other doesn't, form still submit because boolean had been set true, status needed submit.

updated code below, can refer the fiddle.

$(document).ready(function () { $('#myform').submit(function (event) { // todo: check 2 field values match if ($('#myelement1').data('valid') === 'yup' && $('#myelement2').data('valid') === 'yup') { // remove these 3 lines create submit alert('submitting...'); event.preventdefault(); homecoming false; // , uncomment 1 line //return true; } else { event.preventdefault(); homecoming false; } }); $('#myelement1, #myelement2').data('valid', 'nope'); ...

your finish onvalidatepassword callback should this:

'onvalidatepassword': function (strengthpercentage) { $('#' + $(this).data('display')).html( $('#' + $(this).data('display')).html() + ' great, can go on alter password!'); formvalid = strengthpercentage >= 60; // set each element if (strengthpercentage >= 60) { $(this).data('valid', 'yup'); } else { $(this).data('valid', 'nope'); } }

javascript jquery validation jquery-plugins

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -