CHtml::ajax problem with new CJavaScriptExpression #1158

redguy666 opened this Issue Aug 7, 2012 · 2 comments


2 participants

view with code:

echo $form->dropDownList( $model, 'language', CSLangChooser::getLanguages(), array( 'ajax' => array(
        'url'=>$this->createUrl( 'dynamicSections' ),
        'success'=>new CJavaScriptExpression( 'function(html){jQuery("#Content_id_section").html(html).change();}' ),
) ) );

gives error "Method CJavaScriptExpression::__toString() must return a string value" because of double CJavaScriptExpression wrapping...
digging down the problem I have found that responsible is CHtml::ajax function which unnecessary wraps parameter with new CJavascriptExpression:

public static function ajax($options)
        foreach(array('beforeSend','complete','error','success') as $name)
            if(isset($options[$name]) && (!($options[$name] instanceof CJavaScriptExpression) || strpos($options[$name],'js:')!==0))
                $options[$name]=new CJavaScriptExpression($options[$name]);

when 'success' is already wrapped with CJavaScriptExpression, last condition (strpos($options[$name],'js:')!==0) returns TRUE, because strpos returns FALSE ('js:' not found) and FALSE !== 0!!!!

Possible solution: change !== comparison to !=


mdomba commented Aug 7, 2012

This should already be fixed with #1154


mdomba commented Aug 7, 2012

Closing this issue

mdomba closed this Aug 7, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment