-
Notifications
You must be signed in to change notification settings - Fork 4
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
HP-1966: fixed "jquery.js:1468 Uncaught Error: Syntax error, unrecognized expression: .editable[data-pk=][data-name=note]" error which prevents a Playwright test from executing #6
Conversation
…ized expression: .editable[data-pk=][data-name=note]" error which prevents a Playwright test from executing
WalkthroughThe recent change in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($data['model']->primaryKey) { | ||
$selector = ArrayHelper::remove( | ||
$this->pluginOptions, | ||
'selector', | ||
".editable[data-pk={$data['model']->primaryKey}][data-name={$data['attribute']}]", | ||
); | ||
Yii::$app->view->registerJs('$("' . $selector . '").editable(' . Json::htmlEncode($this->pluginOptions) . ');'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure robustness by handling cases where the primary key is not set.
Consider adding an else clause to handle scenarios where $data['model']->primaryKey
is falsy. This could involve logging an error or providing a default behavior to prevent the JavaScript from failing silently.
if ($data['model']->primaryKey) {
$selector = ArrayHelper::remove(
$this->pluginOptions,
'selector',
".editable[data-pk={$data['model']->primaryKey}][data-name={$data['attribute']}]"
);
Yii::$app->view->registerJs('$("' . $selector . '").editable(' . Json::htmlEncode($this->pluginOptions) . ');');
} else {
// Handle the case where primaryKey is not set
Yii::error('Primary key is not set for the model.');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
согласен, а else точно не нужен @VadymHrechukha ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tafid, adding an else
clause can indeed be beneficial, especially for debugging purposes or ensuring that the application behaves predictably even when the primary key is not set. Here's how you might implement it:
if ($data['model']->primaryKey) {
$selector = ArrayHelper::remove(
$this->pluginOptions,
'selector',
".editable[data-pk={$data['model']->primaryKey}][data-name={$data['attribute']}]"
);
Yii::$app->view->registerJs('$("' . $selector . '").editable(' . Json::htmlEncode($this->pluginOptions) . ');');
} else {
// Log an error or handle the case where primaryKey is not set
Yii::error('Primary key is not set for the model.');
// Optionally, you could add a fallback behavior here
}
This approach logs an error when the primary key is not set, which could help in identifying issues during development or in production logs. If there are specific behaviors or fallbacks you'd like to implement in this scenario, those can be added in the else
block as well.
if ($data['model']->primaryKey) { | ||
$selector = ArrayHelper::remove( | ||
$this->pluginOptions, | ||
'selector', | ||
".editable[data-pk={$data['model']->primaryKey}][data-name={$data['attribute']}]", | ||
); | ||
Yii::$app->view->registerJs('$("' . $selector . '").editable(' . Json::htmlEncode($this->pluginOptions) . ');'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
согласен, а else точно не нужен @VadymHrechukha ?
Summary by CodeRabbit