Hi guys,
I’m using the validation plugin from Jquery to be sure that the datas submitted will not be empty.
Everything worked fine with
CHtml::submitButton('Submit')
, but as soon a i changed this
to
CHtml::ajaxSubmitButton('Submit',CController::createUrl('book/add'),array(
'update'=>'#book-div',
'cache'=>true,
'beforeSend' => 'function(){
$("#book-div").addClass("loading");}',
'complete' => 'function(){
$("#book-div").removeClass("loading");}',
),
array(
'id'=>'ajax-book-button',
)
)
, the validation is ignored.
My javascript code:
<script type="text/javascript">
// only for demo purposes
$.metadata.setType("attr", "validate");
$(document).ready(function () {
$("#search-book").validate();
});
</script>
The javascript generated by the AjaxSubmitButton:
<script type="text/javascript">
/*<![CDATA[*/
jQuery(function($) {
jQuery('body').delegate('#submit-book','click',function(){jQuery.ajax({'cache':false,'beforeSend':function(){
$("#book-div").addClass("loading");},'complete':function(){
$("#book-div").removeClass("loading");},'type':'POST','url':'/index.php?r=book/search','data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("#book-div").html(html)}});return false;});
});
/*]]>*/
</script>
Do i miss something here? or do you have an idea how can i keep the validation working even with the Ajax Submit Button ?
Thanks