yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

problem with attributes in mayus like ifToggled activeField #11509

Closed spiritdead closed 8 years ago

spiritdead commented 8 years ago

What steps will reproduce the problem?

im adding attributes with mayus (ifToggled) and this render in lower (iftoggled)

What is the expected result?

if i define in mayus the attribute ifToggled the render display the same result ifToggled

Additional info

Q A
Yii version 2.0.8
PHP version 5.6.x
Operating system win

im using this

<?= $form->field($model,'bird_external')->checkbox(['class' => 'i-checks','ifToggled' => $jsExternals]) ?>

and the render display

<input type="checkbox" id="bird-bird_external" class="i-checks" name="Bird[bird_external]" value="1" iftoggled="    $(&quot;#bird-name&quot;).prop(&quot;disabled&quot;,!this.checked);" style="position: absolute; opacity: 0;">

if can see the attribute iftoggled is lowecapped

steps to reproduce:

add any attribute in mayus, and the rendered is lowercapped

samdark commented 8 years ago

It can't be. We're not transforming attribute case. Most probably you're checking in Chrome web inspector which does that. Check page source instead.

yii-bot commented 8 years ago

This is an automated comment, triggered by adding the label question.

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.

Please use one of the above mentioned resources to discuss the problem. If the result of the discussion turns out that there really is a bug in the framework, feel free to come back and provide information on how to reproduce the issue. This issue will be closed for now.

spiritdead commented 8 years ago

@samdark if i define the attribute

why if this work

$js = <<<JS
    $('input#bird-bird_external').on('ifToggled',function(event){ $("#bird-name").prop("disabled",!this.checked);});
JS;
$this->registerJs($js);

why the other option work and the problem is the uppercase in the params

and is easy reproduce you can confirm fast :/

add any attribute using mayus example

samdark commented 8 years ago

I can't confirm it at all. Please provide steps to reproduce the problem starting with basic app template.

spiritdead commented 8 years ago

@samdark

in the example i used this http://icheck.fronteed.com/

add this in the assets

and a second .js with this

$(document).ready(function () {
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green'
    });
});

the callback ifToggled input's checked state is changed

$jsExternals = 'console.log("hello");';
<?= $form->field($model,'bird_external')->checkbox(['class' => 'i-checks','ifToggled' => $jsExternals]) ?>

you can see if work in the console of the browser, and the event is never fired

but when you add using this method (jquery directly) work

$js = <<<JS
    $('input#bird-bird_external').on('ifToggled',function(event){console.log("hello");});
JS;
$this->registerJs($js);
samdark commented 8 years ago

Well, 'ifToggled' => $jsExternals isn't about event handling at all. It sets attribute value.

samdark commented 8 years ago

If you absolutely want JavaScript in the value, check http://www.yiiframework.com/doc-2.0/yii-web-jsexpression.html