Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

CHtml::ajax problem with new CJavaScriptExpression #1158

Closed
redguy666 opened this Issue · 2 comments

2 participants

@redguy666

view with code:

echo $form->dropDownList( $model, 'language', CSLangChooser::getLanguages(), array( 'ajax' => array(
        'type'=>'POST',
        '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
Collaborator

This should already be fixed with #1154

@mdomba
Collaborator

Closing this issue

@mdomba mdomba closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.