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

HP-2171: autofille move description with order if move description is… #181

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/views/part/create.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
<?php

use hipanel\modules\stock\models\Part;
use yii\web\View;

/**
* @var Part $model
* @var array|Part[] $models
* @var Part[] $models
* @var array $moveTypes
* @var array $suppliers
* @var array $currencyTypes
*/

$this->title = Yii::t('hipanel:stock', 'Create Part');
$this->params['breadcrumbs'][] = ['label' => Yii::t('hipanel:stock', 'Parts'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

$this->registerJs(/** @lang JavaScript */ <<<JS
(() => {
$(document).on("select2:select", "[id$='order_id']", function (event) {
const moveDescriptionField = $(event.target).parents(".item").find("[id$='move_descr']");
if (moveDescriptionField.val().trim() === "") {
moveDescriptionField.val(event.params.data.text);
}
});
})();
JS
,
View::POS_LOAD);
Comment on lines +18 to +29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider optimizing event delegation scope.

While the implementation correctly handles the auto-fill functionality, the event delegation could be more specific for better performance.

Consider scoping the event delegation to the closest static container instead of document:

-  $(document).on("select2:select", "[id$='order_id']", function (event) {
+  $("#part-form").on("select2:select", "[id$='order_id']", function (event) {

This assumes your form has the ID 'part-form'. Please adjust the selector according to your actual form ID.

Committable suggestion skipped: line range outside the PR's diff.


?>

<?= $this->render('_form', compact(['model', 'models', 'moveTypes', 'suppliers', 'currencyTypes'])) ?>
<?= $this->render('_form', [
'model' => $model,
'models' => $models,
'moveTypes' => $moveTypes,
'suppliers' => $suppliers,
'currencyTypes' => $currencyTypes,
]) ?>