Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Id's generated for Ajax button/link etc only unique per view #34

Closed
qiangxue opened this issue Feb 15, 2012 · 0 comments
Closed

Id's generated for Ajax button/link etc only unique per view #34

qiangxue opened this issue Feb 15, 2012 · 0 comments

Comments

@qiangxue
Copy link
Member

What steps will reproduce the problem?
1.Use CJuiTabs etc.
2.Load different forms with Ajax, and CHtml::ajaxXX() functions

What is the expected output? What do you see instead?
expected: The id's generated for Ajax buttons/links etc are unique. Instead
they are only unique for that view.

What version of the product are you using? On what operating system?
1.1RC

Please provide any additional information below.
Perhaps it is better to generate really unique id's for all generated HTML
code (not just per view), especially when there is a JQuery/HTML part
generated. This saves time defining id's in htmlOptions(), and will give
less debugging hassle when using extensive Ajax renderpartials.

Migrated from http://code.google.com/p/yii/issues/detail?id=762


earlier comments

qiang.xue said, at 2009-12-26T22:47:46.000Z:

The only possible way of using unique IDs across different requests is to use session, which will have side effects that we do not like to see.

I would suggest you use jquery's live() method to attach event handlers. I will
change CHtml accordingly to use live() as well.

maxximus007 said, at 2009-12-26T23:15:08.000Z:

Ok, but was thinking a bit simpler: use something like uniqid('yb_'). Live() will not solve the problem with 2 of the same id's in the DOM I suppose.

qiang.xue said, at 2009-12-27T02:19:23.000Z:

Sorry, I didn't read your issue report carefully. You are right that live() doesn't solve your problem since you are referring to different views.

Yes, uniqid could solve the problem as well, but I'm not sure if it will cause any
side effect. Sometimes, we do hope the ID is unchanged.

vuliad said, at 2009-12-27T09:22:15.000Z:

Why not generate random IDs? 'id'=>mt_rand(...) ?

maxximus007 said, at 2009-12-27T11:05:42.000Z:

If you want the ID to be a fixed one, it's easy to define in htmlOptions(). One should not look at a generated ID, expecting it stays the same.

Sure, it's possible already to add your own unique ID with htmlOptions(), but it took
me several hours finding out why things weren't working as expected. Since it's
generated framework code ppl will look at their own code first, before suspecting FW
code. Just trying to prevent others loosing the same hours in the future.

google@zetafleet.com said, at 2010-02-11T09:57:06.000Z:

In cases where the author needs the ID to remain the same it seems that it can always be explicitly set, so I would think that switching to uniqid() would be safe (with some easily fixable breakage for apps that don’t expect it). Worst-case, a parameter could be used to specify whether to use uniqid or the current incremental method, though I would worry that such an option would end up reducing performance for no good reason.

Re comment #4: Random IDs are not the same as unique IDs; uniqid is guaranteed to be
unique, since it is based on time. You could conceivably end up with two identical
values from mt_rand.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant