Commit e5152803 authored by Ana Rute Mendes's avatar Ana Rute Mendes 🌈

CCU: check if fields exist before manipulating them

this avoids javascript errors of object not found when
switching between form types that don't have all the fields
displayed.
parent d99b5350
......@@ -516,7 +516,7 @@ return array(
'rsrc/js/core/phtize.js' => '2f1db1ed',
'rsrc/js/extensions/choices/choices.css' => 'efe1d093',
'rsrc/js/extensions/choices/choices.js' => '3f23770b',
'rsrc/js/extensions/snipe-fields-validation.js' => '057d79f6',
'rsrc/js/extensions/snipe-fields-validation.js' => 'ea38591d',
'rsrc/js/phui/behavior-phui-dropdown-menu.js' => '5cf0501a',
'rsrc/js/phui/behavior-phui-file-upload.js' => 'e150bd50',
'rsrc/js/phui/behavior-phui-selectable-list.js' => 'b26a41e4',
......@@ -911,7 +911,7 @@ return array(
'releeph-request-differential-create-dialog' => '0ac1ea31',
'releeph-request-typeahead-css' => 'bce37359',
'setup-issue-css' => '5eed85b2',
'snipe-fields-validation-js' => '057d79f6',
'snipe-fields-validation-js' => 'ea38591d',
'sprite-login-css' => '18b368a6',
'sprite-tokens-css' => 'f1896dc5',
'syntax-default-css' => '055fc231',
......
......@@ -220,9 +220,11 @@ function fetch_and_hide_extra_assets_elements(index, unique_items) {
asset["asset_tag_parent"].classList.add("snipe_property");
}
asset["item_owner_parent"] = document.getElementsByName(
"std:maniphest:purchasing:item-owner" + index
)[0].parentNode.parentNode;
if (document.getElementsByName("std:maniphest:purchasing:item-owner" + index).length > 0) {
asset["item_owner_parent"] = document.getElementsByName(
"std:maniphest:purchasing:item-owner" + index
)[0].parentNode.parentNode;
}
asset["item_owner_parent"].classList.add("snipe_property");
asset["model_parent"] = document.getElementsByName(
......@@ -236,20 +238,24 @@ function fetch_and_hide_extra_assets_elements(index, unique_items) {
asset["quantity"] = document.getElementsByName(
"std:maniphest:purchasing:quantity" + index
)[0].parentNode.parentNode;
asset["country_of_origin_parent"] = document.getElementsByName(
"std:maniphest:purchasing:country-origin" + index
)[0].parentNode.parentNode;
if (document.getElementsByName("std:maniphest:purchasing:country-origin" + index).length > 0) {
asset["country_of_origin_parent"] = document.getElementsByName(
"std:maniphest:purchasing:country-origin" + index
)[0].parentNode.parentNode;
}
asset["asset_cost_parent"] = document.getElementsByName(
"std:maniphest:purchasing:expected-cost" + index
)[0].parentNode.parentNode;
asset["asset_link_parent"] = document.getElementsByName(
"std:maniphest:purchasing:item-link" + index
)[0].parentNode.parentNode;
asset["asset_currency_parent"] = document.getElementsByName(
"std:maniphest:purchasing:currency" + index
)[0].parentNode.parentNode;
if (document.getElementsByName("std:maniphest:purchasing:item-link" + index).length > 0) {
asset["asset_link_parent"] = document.getElementsByName(
"std:maniphest:purchasing:item-link" + index
)[0].parentNode.parentNode;
};
if (document.getElementsByName("std:maniphest:purchasing:currency" + index).length > 0) {
asset["asset_currency_parent"] = document.getElementsByName(
"std:maniphest:purchasing:currency" + index
)[0].parentNode.parentNode;
};
if (document.getElementsByName("std:maniphest:purchasing:serial" + index).length > 0) {
asset["asset_serial_parent"] = document.getElementsByName(
"std:maniphest:purchasing:serial" + index
......@@ -330,6 +336,9 @@ function purchasing_validations() {
}
};
if (document.getElementsByName("__submit__").length === 0) {
return;
}
submit_parent = document.getElementsByName("__submit__")[0].parentNode
.parentNode;
add_new_asset = document.createElement("div");
......@@ -340,6 +349,9 @@ function purchasing_validations() {
add_new_asset_btn.onclick = function (e) {
e.preventDefault();
if (!num_asset_forms.value) {
num_asset_forms.value = 1;
};
if (num_asset_forms.value < MAX_ALLOWED_ASSETS) {
for (let key in assets_list[num_asset_forms.value - 1]) {
if (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment