Jquery Steps and FormValidation (re-validate) -
i using jquery steps , formvalidation when onstepchanged cannot re-validate fields.
onstepchanging: function(e, currentindex, newindex) { var fv = $('#form1').data('formvalidation'), // formvalidation instance // current step container $container = $('#form1').find('section[data-step="' + currentindex +'"]'); // validate container fv.validatecontainer($container); var isvalidstep = fv.isvalidcontainer($container); if (isvalidstep === false || isvalidstep === null) { // not jump next step return false; } if (currentindex === 3) { // form $.ajax({ type: "post", url: url, data: $('#form1').serialize(), datatype: 'json', cache: false, async: false, success: function(data){ if (data.result === 'error') { (var field in data.fields) { $('#'+field).val(''); $('#form1').formvalidation('revalidatefield', field) } $('#form1').steps("previous"); return; } else { console.log('success'); } }, error: function(x, status, error) { return false; }, }); } return true; }
the inputs empty not re-validated!
i tried (updatestatus , validatefield) no success!! whats going wrong!
updated
jsfiddle: demo
on step 3 (confirmation) iam making post server side process data (product stock, shipping etc..) if validation process didn't pass go step 1 or 2 , re-enter data. or if validation process ok show result on step 3 , allow user finish(submit form).
php code:
$result = "error"; $fields = array( 'product' => 'out of stock', 'id' => 'id not found', ); $response = array('html'=>$html, 'result'=>$result, 'fields'=>$fields); echo json_encode($response);
you have errors in code:
1.
// here, should use `newindex` instead of `curentindex` // note index of step goes `0` `count(steps) - 1` if (newindex === 2) {}
2.
// excluded: [':disabled', ':hidden', ':not(:visible)'], // should => // have exclude disabled fields // when navigate between steps, fields of hidden steps // hidden , not visible formvalidation plugin, // should include them. excluded: [':disabled'],
# working example: https://jsfiddle.net/arkni/qtngbsy9/
Comments
Post a Comment