Note that there are some explanatory texts on larger screens.

plurals
  1. POYii ajaxSubmitButton() with fields validation
    primarykey
    data
    text
    <p>I'm using Yii ajaxSubmitButton() to submit a form. Besides, I have set the 'enableAjaxValidation' parameter to true to validate the corresponding textboxes.</p> <p>What I am able to do:</p> <ol> <li>Validate the field when the focus leaves it, asynchronously.</li> <li>Invoke the server side method when the button is clicked, asynchronously.</li> </ol> <p>The problem is that I don't know how to perform the fields validation when the submit button is clicked and, if the model is validated, perform a partial rendering in client side.</p> <p>If I override the 'success' event in ajaxSubmitButton, I get the partial rendering, but I can't maintain the model validation..</p> <p>Any help?</p> <hr> <p>EDIT</p> <p>Thanks for the reply,</p> <p>The validateOnSubmit flag is already set and the model would be validated correctly if the 'success' event was not set.</p> <p>When the ajaxSubmitButton is like this:</p> <pre><code>&lt;?php echo CHtml::ajaxSubmitButton( 'Send', CHtml::normalizeUrl(array('site/ajaxIndexSubmit')), array( 'error'=&gt;'js:function(){ alert(\'error\'); }', 'beforeSend'=&gt;'js:function(){ alert(\'beforeSend\'); }', 'success'=&gt;'js:function(data){ alert(\'success, data from server: \'+data); }', 'complete'=&gt;'js:function(){ alert(\'complete\'); }', //'update'=&gt;'#where_to_put_the_response', ) ); ?&gt; </code></pre> <p>the alert('success') will print the string corresponding to the model validation. Once I have that string, what logic must be invoken in client side?</p> <p>The reason to override the 'success' javascript handler is to receive a partial rendering from the server, different to the model validation. I want both things: validation and partial rendering.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload