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

clickableSelector and changeableSelector options are not configurable in yii.js #13295

Open arogachev opened 7 years ago

arogachev commented 7 years ago

I found this issue during writing tests for yii.js.

We have these 2 properties in window.yii:

/**
 * The selector for clickable elements that need to support confirmation and form submission.
 */
clickableSelector: 'a, button, input[type="submit"], input[type="button"], input[type="reset"], input[type="image"]',
/**
 * The selector for changeable elements that need to support confirmation and form submission.
*/
changeableSelector: 'select, input, textarea',

Even they are publicly accessible and settable through window.yii, custom values will have no effect.

 $(document).on('click.yii', pub.clickableSelector, handler)
    .on('change.yii', pub.changeableSelector, handler);

The releavant code immediately called right on when document is ready:

jQuery(function () {
    yii.initModule(yii);
});

And event handlers will stay bound to elements found by initial selector.

So we need either to make them configurable or not expose it as public variables because it does not make sense.

P.S. This does not apply to reloadableScripts property because it's checked everytime in isReloadable() function.

samdark commented 7 years ago

I think these are internal things so probably should not be exposed at all...

arogachev commented 7 years ago

@samdark Even it's rare case and this setup can be sufficient for the majority of the users, I think configuring them can be useful. User may want to remove some elements (in case of some conflicts with existing JS maybe):

yii.changeableSelector: 'select, input'

or have general setup based on classes:

yii.clickableSelector = 'clickable';
yii.changeableSelector = 'changeable';
samdark commented 7 years ago

OK. That won't hurt at least. I'm fine having these.