Skip to content

Commit 5467986

Browse files
committed
feat: supporting multiple specs with same grid on product form
1 parent 6f0745c commit 5467986

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/controllers/resources/form/products.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,12 @@ export default function () {
155155
for (gridId in specifications) {
156156
var specArray = specifications[gridId]
157157
if (Array.isArray(specArray)) {
158-
// add one spec object per grid only
159-
var specValue = addSpec(gridId, 'spec', true)
160-
if (specValue) {
161-
specValue(specArray[0].text)
162-
}
158+
specArray.forEach(({ text }) => {
159+
var specValue = addSpec(gridId, 'spec', true)
160+
if (specValue) {
161+
specValue(text)
162+
}
163+
})
163164
}
164165
}
165166
}
@@ -1843,10 +1844,6 @@ export default function () {
18431844
$input = $specs.find('input').filter(function () {
18441845
return $(this).data('grid') === gridId
18451846
})
1846-
if ($input.length) {
1847-
$input.focus()
1848-
return
1849-
}
18501847
// create DOM elements for specification grid
18511848
$input = $('<input>', {
18521849
class: 'form-control',
@@ -1942,9 +1939,7 @@ export default function () {
19421939

19431940
if (!skipData) {
19441941
// mount specification object
1945-
var specObject = {
1946-
text: text
1947-
}
1942+
var specObject = { text }
19481943
// optional value
19491944
if (value) {
19501945
specObject.value = value
@@ -2050,22 +2045,20 @@ export default function () {
20502045
const hourPattern = hasHourPattern ? ' 99:99:99' : ''
20512046
if (hasHourPattern) {
20522047
$(`#t${tabId}-price-effective-dates`)
2053-
.val(null)
2054-
.inputmask(lang === 'pt_br' ? `99/99/9999${hourPattern} ~ 99/99/9999${hourPattern}` : `99-99-9999${hourPattern} ~ 99-99-9999${hourPattern}`)
2048+
.val(null)
2049+
.inputmask(lang === 'pt_br' ? `99/99/9999${hourPattern} ~ 99/99/9999${hourPattern}` : `99-99-9999${hourPattern} ~ 99-99-9999${hourPattern}`)
20552050
}
20562051
})
20572052
const parseHourDate = (dateStr) => {
2058-
const [datePart, timePart] = dateStr.split(' ');
2059-
const [day, month, year] = datePart.split(/[/-]/).map(s => Number(s));
2060-
2053+
const [datePart, timePart] = dateStr.split(' ')
2054+
const [day, month, year] = datePart.split(/[/-]/).map(s => Number(s))
20612055
if (timePart) {
2062-
const [hour, min, sec] = timePart.split(':').map(s => Number(s));
2063-
return { day, month, year, hour, min, sec };
2056+
const [hour, min, sec] = timePart.split(':').map(s => Number(s))
2057+
return { day, month, year, hour, min, sec }
20642058
}
2065-
2066-
return { day, month, year };
2059+
return { day, month, year }
20672060
}
2068-
2061+
20692062
const $priceEffectiveDates = $(`#t${tabId}-price-effective-dates`)
20702063
.inputmask(lang === 'pt_br' ? `99/99/9999 ~ 99/99/9999` : `99-99-9999 ~ 99-99-9999`)
20712064
.change(function () {

0 commit comments

Comments
 (0)