javascript - validationEngine('validate') not a function -
i have simple form want know if form @ valid state or not.
this project using jquery validation engine
i using same version 2.6.2
according docs supports function validationengine('validate')
returns true or false depending on state of form.
i keep getting error typeerror: $(...).validationengine not function
strangely enough form throwing validation errors required.
i did check validationengine plugin loaded after jquery , before js file triggering call. form selector correct.
the form:
<form name="editprofileform" method="post" action="#" class="epf" id="editdiaryform" style="display:none;"> <a href="javascript:void(0)" onclick="togglecancel(this,'addplay');$('#editdiaryform')[0].reset();;" class="pull-right action-link">cancel</a> <a href="javascript:void(0)" onclick="submitdiary('#editdiaryform');" class="pull-right action-link">save </a> <input class="form-control validate[required, ajax[ajaxdiarycall]]" name="title" id="title" type="text"/> <textarea class="form-control validate[required]" name="playdiary" id="playdiary"></textarea> <input type="hidden" name="edit" value="playdiary" /> </form>
attaching validation:
$(document).ready(function(){ $("#editdiaryform").validationengine('attach'); //this throws true console.log($('#editdiaryform').validationengine('validate')); });
the submit function
function submitdiary(formid) { $(formid).bind('submit' , function(e){ e.preventdefault(); // gives me expected value console.log('submiting form - '+ formid); //throws me error here if commited $(formid).validationengine(); submit = false; //gets stuck here if(submit == false && $(formid).validationengine('validate') == true) { submit=true; $.ajax({ url: url+'diary/save', async: false, type: "post", data: $(formid).serialize(), success: function (data) { if(data==true) { $('#diaries').prepend(data); } else { custom_page_msg('something went wrong. please login account again complete action.'); } submit = false; } }); } }); $(formid).submit(); }
script order
<script src="<?php echo base_url()?>js/jquery.min.js"></script> <!-- include compiled plugins (below), or include individual files needed --> <script src="<?php echo base_url('js'); ?>/bootstrap.min.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script src="<?php echo base_url('js/languages'); ?>/jquery.validationengine-en.js"></script> <script src="<?php echo base_url('js'); ?>/jquery.validationengine.js"></script> <script src="<?php echo base_url('js'); ?>/jquery.customselect.min.js"></script> <script src="<?php echo base_url('js'); ?>/scripts.js"></script> <script src="<?php echo base_url('js'); ?>/other-validation.js"></script> <script src="<?php echo base_url('js'); ?>/dropzone.js"></script> <script src="<?php echo base_url('js'); ?>/global.js"></script>
any guidence in regards helpful.
update
its solved issue elsewhere. found file loading own version of js. simple jquery.noconflict();
@ start of submitdiary function did trick. if run silimar might it.
thanks.
ok problem trying call function when jquery not ready, best whey have sync. process bind click event on buttons, , on click handle data.
bellow have simple example working.
$(function(){ $("#editdiaryform").validationengine('attach'); console.log("here type of validationengine: ", typeof $("#editdiaryform").validationengine); $('#test').bind('click', function(e) { e.preventdefault(); $(this).parent('form').validationengine('validate'); }); });
<html> <head> </head> <body> <form name="editprofileform" method="post" action="#" class="epf" id="editdiaryform"> <a id="test" href="#" class="pull-right action-link">save </a> </form> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-engine/2.6.2/jquery-1.8.2.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-engine/2.6.2/languages/jquery.validationengine-en.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-engine/2.6.2/jquery.validationengine.min.js"></script> </body> </html>
Comments
Post a Comment